1
0
mirror of https://gitlab.gnome.org/GNOME/libxml2.git synced 2024-10-26 12:25:09 +03:00

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
This commit is contained in:
Daniel Veillard 2013-05-10 14:01:46 +08:00
parent 1ba80b7b6f
commit 63588f476f
4 changed files with 47 additions and 0 deletions

View File

@ -10681,6 +10681,10 @@ xmlParseDocument(xmlParserCtxtPtr ctxt) {
ctxt->sax->startDocument(ctxt->userData);
if (ctxt->instate == XML_PARSER_EOF)
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

17
xmlIO.c
View File

@ -2668,6 +2668,12 @@ __xmlParserInputBufferCreateFilename(const char *URI, xmlCharEncoding enc) {
}
#endif
}
#endif
#ifdef HAVE_LZMA_H
if ((xmlInputCallbackTable[i].opencallback == xmlXzfileOpen) &&
(strcmp(URI, "-") != 0)) {
ret->compressed = __libxml2_xzcompressed(context);
}
#endif
}
else
@ -3325,6 +3331,17 @@ xmlParserInputBufferGrow(xmlParserInputBufferPtr in, int len) {
if (res < 0) {
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;
if (in->encoder != NULL) {
unsigned int use;

25
xzlib.c
View File

@ -182,12 +182,37 @@ xz_open(const char *path, int fd, const char *mode ATTRIBUTE_UNUSED)
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
__libxml2_xzopen(const char *path, const char *mode)
{
return xz_open(path, -1, mode);
}
int
__libxml2_xzcompressed(xzFile f) {
return xz_compressed(f);
}
xzFile
__libxml2_xzdopen(int fd, const char *mode)
{

View File

@ -15,4 +15,5 @@ xzFile __libxml2_xzopen(const char *path, const char *mode);
xzFile __libxml2_xzdopen(int fd, const char *mode);
int __libxml2_xzread(xzFile file, void *buf, unsigned len);
int __libxml2_xzclose(xzFile file);
int __libxml2_xzcompressed(xzFile f);
#endif /* LIBXML2_XZLIB_H */