Hi,
just found one more bug in LZW decompression. With fix suggestion, of course :-)
File: PdfFiltersPrivate.cpp
Bug: class PdfLZWFilter is unable to create 0xff bytes in decoded LZW streams.
This is obviously not relevant for compressed text streams (99.9% of all
cases), but is important when image data is LZW-encoded. (No one should use LZW
on inlined image data nowadays, but some strange workflow software still does.)
Explanation: The current default decoding dictionary (created in
PdfLZWFilter::InitTable) maps code:0xff to cleartext:<two bytes derived from an
PdfLZWFilter constant>. Thus, any (0*)-1111-1111 bit sequence in the LZW stream
is decoded as two(!) bytes, which is not correct: it's impossible to create
0xff bytes in the output stream, and the output data even may become longer as
expected. Any n-bit-sequence s for which s==(s&0xff) holds, should be an
identity. Just the sequences where s!=(s&0xff) - where bit 9 (or any higher
bit) is set - are codes for multibyte sequences.
Suggested fix: the loop counter should run to (including!) 255 to form the
completed identity function. To keep the table size after "InitTable()" exactly
the same, just one "dummy" entry is added (no content needed here: 0x100 is
magic for "clear dictionary" - the encoder will never use this code as an
abbreviation, so this table entry value is never used: The entry is just for
correct counting of the dictionary size).
Changed code:
-----X-----
void PdfLZWFilter::InitTable()
{
int i;
TLzwItem item;
m_table.clear();
m_table.reserve( LZW_TABLE_SIZE );
for( i=0;i<=255;i++ )
{
item.value.clear();
item.value.push_back( static_cast<unsigned char>(i) );
m_table.push_back( item );
}
item.value.clear();
m_table.push_back( item );
}
-----X-----
Regards,
Johannes
------------------------------------------------------------------------------
Sell apps to millions through the Intel(R) Atom(Tm) Developer Program
Be part of this innovative community and reach millions of netbook users
worldwide. Take advantage of special opportunities to increase revenue and
speed time-to-market. Join now, and jumpstart your future.
http://p.sf.net/sfu/intel-atom-d2d
_______________________________________________
Podofo-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/podofo-users