tecnickcom / TCPDF

Official clone of PHP library to generate PDF documents and barcodes
https://tcpdf.org
Other
4.18k stars 1.51k forks source link

Wrong /Length calculation in xobjects #723

Open crThiago opened 4 months ago

crThiago commented 4 months ago

The method _putxobjects calculate the stream length:

1 - $stream = $this->_getrawstream($stream, $data['n']);
2 - $out .= ' /Length '.strlen($stream);
3 - $out .= ' >>';
4 - $out .= ' stream'."\n".$stream."\n".'endstream'; // INCREMENTED MORE BYTES HERE
5 - $out .= "\n".'endobj';
6 - $this->_out($out);

but on line 4 $out .= ' stream'."\n".$stream."\n".'endstream'; is incremented more bytes (\n) resulting in a wrong calculation

Sugestion

Move the break line from line 4 to line 1:

1 - $stream = "\n" . $this->_getrawstream($stream, $data['n']) . "\n";
2 - $out .= ' /Length '.strlen($stream);
3 - $out .= ' >>';
4 - $out .= ' stream' . $stream . 'endstream';