Blame SOURCES/libxml2-Fix-a-regression-in-xmlGetDocCompressMode.patch

6dedca
From 268e6a3d615a14c6f6f1e8cf3d8c1e5c42ad1b41 Mon Sep 17 00:00:00 2001
6dedca
From: Daniel Veillard <veillard@redhat.com>
6dedca
Date: Fri, 10 May 2013 14:01:46 +0800
6dedca
Subject: [PATCH] Fix a regression in xmlGetDocCompressMode()
6dedca
To: libvir-list@redhat.com
6dedca
6dedca
The switch to xzlib had for consequence that the compression
6dedca
level of the input was not gathered anymore in ctxt->input->buf,
6dedca
then the parser compression flags was left to -1 and propagated
6dedca
to the resulting document.
6dedca
Fix the I/O layer to get compression detection in xzlib,
6dedca
then carry it in the input buffer and the resulting document
6dedca
6dedca
  This should fix
6dedca
    https://lsbbugs.linuxfoundation.org/show_bug.cgi?id=3456
6dedca
6dedca
Signed-off-by: Daniel Veillard <veillard@redhat.com>
6dedca
---
6dedca
 parser.c |  4 ++++
6dedca
 xmlIO.c  | 17 +++++++++++++++++
6dedca
 xzlib.c  | 25 +++++++++++++++++++++++++
6dedca
 xzlib.h  |  1 +
6dedca
 4 files changed, 47 insertions(+)
6dedca
6dedca
diff --git a/parser.c b/parser.c
6dedca
index ee429f3..f30588c 100644
6dedca
--- a/parser.c
6dedca
+++ b/parser.c
6dedca
@@ -10681,6 +10681,10 @@ xmlParseDocument(xmlParserCtxtPtr ctxt) {
6dedca
         ctxt->sax->startDocument(ctxt->userData);
6dedca
     if (ctxt->instate == XML_PARSER_EOF)
6dedca
 	return(-1);
6dedca
+    if ((ctxt->myDoc != NULL) && (ctxt->input != NULL) &&
6dedca
+        (ctxt->input->buf != NULL) && (ctxt->input->buf->compressed >= 0)) {
6dedca
+	ctxt->myDoc->compression = ctxt->input->buf->compressed;
6dedca
+    }
6dedca
 
6dedca
     /*
6dedca
      * The Misc part of the Prolog
6dedca
diff --git a/xmlIO.c b/xmlIO.c
6dedca
index 847cb7e..fc4e111 100644
6dedca
--- a/xmlIO.c
6dedca
+++ b/xmlIO.c
6dedca
@@ -2669,6 +2669,12 @@ __xmlParserInputBufferCreateFilename(const char *URI, xmlCharEncoding enc) {
6dedca
 #endif
6dedca
 	}
6dedca
 #endif
6dedca
+#ifdef HAVE_LZMA_H
6dedca
+	if ((xmlInputCallbackTable[i].opencallback == xmlXzfileOpen) &&
6dedca
+		(strcmp(URI, "-") != 0)) {
6dedca
+            ret->compressed = __libxml2_xzcompressed(context);
6dedca
+	}
6dedca
+#endif
6dedca
     }
6dedca
     else
6dedca
       xmlInputCallbackTable[i].closecallback (context);
6dedca
@@ -3325,6 +3331,17 @@ xmlParserInputBufferGrow(xmlParserInputBufferPtr in, int len) {
6dedca
     if (res < 0) {
6dedca
 	return(-1);
6dedca
     }
6dedca
+
6dedca
+    /*
6dedca
+     * try to establish compressed status of input if not done already
6dedca
+     */
6dedca
+    if (in->compressed == -1) {
6dedca
+#ifdef HAVE_LZMA_H
6dedca
+	if (in->readcallback == xmlXzfileRead)
6dedca
+            in->compressed = __libxml2_xzcompressed(in->context);
6dedca
+#endif
6dedca
+    }
6dedca
+
6dedca
     len = res;
6dedca
     if (in->encoder != NULL) {
6dedca
         unsigned int use;
6dedca
diff --git a/xzlib.c b/xzlib.c
6dedca
index 928bd17..150e803 100644
6dedca
--- a/xzlib.c
6dedca
+++ b/xzlib.c
6dedca
@@ -182,12 +182,37 @@ xz_open(const char *path, int fd, const char *mode ATTRIBUTE_UNUSED)
6dedca
     return (xzFile) state;
6dedca
 }
6dedca
 
6dedca
+static int
6dedca
+xz_compressed(xzFile f) {
6dedca
+    xz_statep state;
6dedca
+
6dedca
+    if (f == NULL)
6dedca
+        return(-1);
6dedca
+    state = (xz_statep) f;
6dedca
+    if (state->init <= 0)
6dedca
+        return(-1);
6dedca
+
6dedca
+    switch (state->how) {
6dedca
+        case COPY:
6dedca
+	    return(0);
6dedca
+	case GZIP:
6dedca
+	case LZMA:
6dedca
+	    return(1);
6dedca
+    }
6dedca
+    return(-1);
6dedca
+}
6dedca
+
6dedca
 xzFile
6dedca
 __libxml2_xzopen(const char *path, const char *mode)
6dedca
 {
6dedca
     return xz_open(path, -1, mode);
6dedca
 }
6dedca
 
6dedca
+int
6dedca
+__libxml2_xzcompressed(xzFile f) {
6dedca
+    return xz_compressed(f);
6dedca
+}
6dedca
+
6dedca
 xzFile
6dedca
 __libxml2_xzdopen(int fd, const char *mode)
6dedca
 {
6dedca
diff --git a/xzlib.h b/xzlib.h
6dedca
index 43c75e1..29ba55e 100644
6dedca
--- a/xzlib.h
6dedca
+++ b/xzlib.h
6dedca
@@ -15,4 +15,5 @@ xzFile __libxml2_xzopen(const char *path, const char *mode);
6dedca
 xzFile __libxml2_xzdopen(int fd, const char *mode);
6dedca
 int __libxml2_xzread(xzFile file, void *buf, unsigned len);
6dedca
 int __libxml2_xzclose(xzFile file);
6dedca
+int __libxml2_xzcompressed(xzFile f);
6dedca
 #endif /* LIBXML2_XZLIB_H */
6dedca
-- 
6dedca
1.8.3.1
6dedca