art1c0 / mooha

Automatically exported from code.google.com/p/mooha
0 stars 0 forks source link

Errors in Encode.php #3

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Encode.php: class XML_WBXML_Encoder

WITH ERRORS
======================

function writeStringTable($strings, $charset, $stringTable)
    {
        $stringBytes = array();
        $count = 0;
        foreach ($strings as $str) {
            $bytes = $this->_getBytes($str, $charset);
            $stringBytes = array_merge($stringBytes, $bytes);
            $nullLength = $this->_addNullByte($bytes);   // <- ERROR
            $this->_stringTable->set($str, $count);
            $count += count($bytes) + $nullLength;  // <- ERROR
        }

        XML_WBXML::intToMBUInt32($this->_output, count($stringBytes));
        $this->_output .= implode('', $stringBytes);
    }

WITHOUT ERRORS
====================

function writeStringTable($strings, $charset, $stringTable)
    {
        $stringBytes = array();
        $count = 0;
        foreach ($strings as $str) {
            $bytes = $this->_getBytes($str, $charset);
        $nullLength = $this->_addNullByte($bytes);  // <- OK
            $stringBytes = array_merge($stringBytes, $bytes);
            //$nullLength = $this->_addNullByte($bytes);
            $this->_stringTable->set($str, $count);
            //$count += count($bytes) + $nullLength;
        $count += count($bytes);  // <- OK
        }

        XML_WBXML::intToMBUInt32($this->_output, count($stringBytes));
        $this->_output .= implode('', $stringBytes);
    }

Original issue reported on code.google.com by and...@hisinfo.org on 15 Mar 2010 at 8:26

GoogleCodeExporter commented 9 years ago
Thank you for your fix, Andrey!
Note that this WBXML encoder/decoder was used from the Horde framework as you 
can see
from the copyright (it is licenced under LGPL so it is open).
But in any case it is much better to use system WBXML tools like wbxml2xml &
xml2wbxml to avoid such kind of bugs.
Fixed in rev.38

Original comment by artico.b...@gmail.com on 17 Mar 2010 at 7:13