xzyang / rpms / libxml2

Forked from rpms/libxml2 3 years ago
Clone

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

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