After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 440159 - Logic error in xmlCharEncFirstLine
Logic error in xmlCharEncFirstLine
Status: RESOLVED FIXED
Product: libxml2
Classification: Platform
Component: general
git master
Other Mac OS
: Normal trivial
: ---
Assigned To: Daniel Veillard
libxml QA maintainers
Depends on:
Blocks:
 
 
Reported: 2007-05-21 12:18 UTC by Mark Rowe
Modified: 2007-05-22 16:05 UTC
See Also:
GNOME target: ---
GNOME version: ---



Description Mark Rowe 2007-05-21 12:18:10 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,
Comment 1 William M. Brack 2007-05-21 16:28:04 UTC
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.
Comment 2 Mark Rowe 2007-05-21 23:31:15 UTC
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,
Comment 3 William M. Brack 2007-05-22 16:05:53 UTC
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.