Commit 63588f47 authored by Daniel Veillard's avatar Daniel Veillard

Fix a regression in xmlGetDocCompressMode()

The switch to xzlib had for consequence that the compression
level of the input was not gathered anymore in ctxt->input->buf,
then the parser compression flags was left to -1 and propagated
to the resulting document.
Fix the I/O layer to get compression detection in xzlib,
then carry it in the input buffer and the resulting document

  This should fix
    https://lsbbugs.linuxfoundation.org/show_bug.cgi?id=3456
parent 1ba80b7b
...@@ -10681,6 +10681,10 @@ xmlParseDocument(xmlParserCtxtPtr ctxt) { ...@@ -10681,6 +10681,10 @@ xmlParseDocument(xmlParserCtxtPtr ctxt) {
ctxt->sax->startDocument(ctxt->userData); ctxt->sax->startDocument(ctxt->userData);
if (ctxt->instate == XML_PARSER_EOF) if (ctxt->instate == XML_PARSER_EOF)
return(-1); return(-1);
if ((ctxt->myDoc != NULL) && (ctxt->input != NULL) &&
(ctxt->input->buf != NULL) && (ctxt->input->buf->compressed >= 0)) {
ctxt->myDoc->compression = ctxt->input->buf->compressed;
}
/* /*
* The Misc part of the Prolog * The Misc part of the Prolog
......
...@@ -2668,6 +2668,12 @@ __xmlParserInputBufferCreateFilename(const char *URI, xmlCharEncoding enc) { ...@@ -2668,6 +2668,12 @@ __xmlParserInputBufferCreateFilename(const char *URI, xmlCharEncoding enc) {
} }
#endif #endif
} }
#endif
#ifdef HAVE_LZMA_H
if ((xmlInputCallbackTable[i].opencallback == xmlXzfileOpen) &&
(strcmp(URI, "-") != 0)) {
ret->compressed = __libxml2_xzcompressed(context);
}
#endif #endif
} }
else else
...@@ -3325,6 +3331,17 @@ xmlParserInputBufferGrow(xmlParserInputBufferPtr in, int len) { ...@@ -3325,6 +3331,17 @@ xmlParserInputBufferGrow(xmlParserInputBufferPtr in, int len) {
if (res < 0) { if (res < 0) {
return(-1); return(-1);
} }
/*
* try to establish compressed status of input if not done already
*/
if (in->compressed == -1) {
#ifdef HAVE_LZMA_H
if (in->readcallback == xmlXzfileRead)
in->compressed = __libxml2_xzcompressed(in->context);
#endif
}
len = res; len = res;
if (in->encoder != NULL) { if (in->encoder != NULL) {
unsigned int use; unsigned int use;
......
...@@ -182,12 +182,37 @@ xz_open(const char *path, int fd, const char *mode ATTRIBUTE_UNUSED) ...@@ -182,12 +182,37 @@ xz_open(const char *path, int fd, const char *mode ATTRIBUTE_UNUSED)
return (xzFile) state; return (xzFile) state;
} }
static int
xz_compressed(xzFile f) {
xz_statep state;
if (f == NULL)
return(-1);
state = (xz_statep) f;
if (state->init <= 0)
return(-1);
switch (state->how) {
case COPY:
return(0);
case GZIP:
case LZMA:
return(1);
}
return(-1);
}
xzFile xzFile
__libxml2_xzopen(const char *path, const char *mode) __libxml2_xzopen(const char *path, const char *mode)
{ {
return xz_open(path, -1, mode); return xz_open(path, -1, mode);
} }
int
__libxml2_xzcompressed(xzFile f) {
return xz_compressed(f);
}
xzFile xzFile
__libxml2_xzdopen(int fd, const char *mode) __libxml2_xzdopen(int fd, const char *mode)
{ {
......
...@@ -15,4 +15,5 @@ xzFile __libxml2_xzopen(const char *path, const char *mode); ...@@ -15,4 +15,5 @@ xzFile __libxml2_xzopen(const char *path, const char *mode);
xzFile __libxml2_xzdopen(int fd, const char *mode); xzFile __libxml2_xzdopen(int fd, const char *mode);
int __libxml2_xzread(xzFile file, void *buf, unsigned len); int __libxml2_xzread(xzFile file, void *buf, unsigned len);
int __libxml2_xzclose(xzFile file); int __libxml2_xzclose(xzFile file);
int __libxml2_xzcompressed(xzFile f);
#endif /* LIBXML2_XZLIB_H */ #endif /* LIBXML2_XZLIB_H */
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment