GNOME Bugzilla – Bug 440159
Logic error in xmlCharEncFirstLine
Last modified: 2007-05-22 16:05:53 UTC
xmlCharEncFirstLine initialises 'written' to the amount of free space in the output buffer, then overwrites it with the value of 45 (the number of bytes to start converting). The number of bytes to convert should be stored in 'toconv', which is instead left uninitialized. As far as I can see this has no visible impact with the standard encoding conversion routines, but the code seems obviously incorrect. Patch is included below. diff --git a/libxml2/encoding.c b/libxml2/encoding.c index 859bac6..0c92481 100644 --- a/libxml2/encoding.c +++ b/libxml2/encoding.c @@ -1890,7 +1890,7 @@ xmlCharEncFirstLine(xmlCharEncodingHandler *handler, xmlBufferPtr out, * 45 chars should be sufficient to reach the end of the encoding * declaration without going too far inside the document content. */ - written = 45; + toconv = 45; if (handler->input != NULL) { ret = handler->input(&out->content[out->use], &written,
Before I comment on the validity of the above (which I belienve is incorrect), could you please check what version of the source you are referring to? Current SVN for encoding.c (rev 3617) has a line number which differs by more than 100 from what you are quoting.
My apologies. The patch I created was from a tree based on libxml2-2.6.27 with support for encoding conversion via ICU, which accounts for the line number mismatch. The patch below is from a clean tree: diff --git a/encoding.c b/encoding.c index ee33df1..14ddc13 100644 --- a/encoding.c +++ b/encoding.c @@ -1773,7 +1773,7 @@ xmlCharEncFirstLine(xmlCharEncodingHandler *handler, xmlBufferPtr out, * 45 chars should be sufficient to reach the end of the encoding * declaration without going too far inside the document content. */ - written = 45; + toconv = 45; if (handler->input != NULL) { ret = handler->input(&out->content[out->use], &written,
OK, I agree. I did a little further enhancement to your proposed change. The changed code is in SVN (rev 3618). Thanks for the report.