Open tommynovember7 opened 6 years ago
Hi !
It's not enough.
Function getDictValue() is also bugged and do the same bug at same line.
For example, consider this PDF data sample :
<<
/Type /XObject
/Width 93
/Filter [/FlateDecode]
/Height 93
/Length 1930
/Subtype /Image
/ColorSpace [/Indexed /DeviceRGB 255 ( \b\b\b\n\n\n\r\r\r\t\t\tÔ ³½ µ» ·¹°¿ ´¼>>>???888!!!&&&\(\(\(###%%%===555$$$///999333\)\)\)""";;;666111''':::222444\)1ÿ3;ÿ9?ÿ?Wø9@ÿ>Fÿ;]ô>Eÿ?Fÿ?Vø:Aÿ5fï2iìDDDEEELLLNNNTTT[[[ZZZHHHMMMQQQGGGCCC___VVVYYYFFFBBBWWWIIISSSFMÿ@GÿENþGLÿX_ÿEMÿTZÿDLÿaaacccqqqooommmfffkkkjjjggg}}}hhhddduuuwwwsssnnniii~~~rrrpppbbbyyy{{{````fÿ`eÿgmÿ›››œœœ˜˜˜ƒƒƒšššŒŒŒ’’’‚‚‚†††ŽŽŽ•••———–––‡‡‡“““‰‰‰ŸŸŸ”””‹‹‹†ÿƒˆÿ›žÿž¢ÿ ¿¿¿½½½³³³···¦¦¦ªªª¾¾¾©©©¡¡¡°°°¥¥¥¨¨¨¶¶¶µµµ¤¤¤´´´±±±²²²¼¼¼®®®¯¯¯¸¸¸°ÿªÿ¶¸ÿ¸ºÿ¼¿ÿ©¬ÿ¸»ÿª®ÿÇÇÇÆÆÆ×××ÉÉÉØØØÙÙÙÝÝÝÛÛÛÓÓÓÁÁÁÖÖÖÊÊÊÜÜÜÒÒÒÌÌÌÔÔÔÚÚÚËËËÀÀÀÂÂÂÍÍÍÈÈÈÅÅÅÄÄÄÑÑÑÛÜÿùùùõõõøøøôôôòòòóóóüüüýýýìììúúú÷÷÷éééêêêûûûöööçççëëëþþþíííññÿýýÿäääåçÿüýÿåæÿîîîàààñññèèèÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ)]
/BitsPerComponent 8
>>
The function will not work properly because string ">>" is present inside the last crochets (crochets of ColorSpace)
Suggested modification :
private function getDictValue($offset, &$data) {
$objval = array();
// Extract dict from data
$i = 1;
$dict = "";
$offset+= 2;
$is_bracket = false;
do {
if ($data[$offset] == "[") {
$is_bracket = true;
$dict.= $data[$offset];
} else if ($data[$offset] == "]") {
$is_bracket = false;
$dict.= $data[$offset];
} else if (!$is_bracket && ($data[$offset] == "<") && ($data[$offset + 1] == "<")) {
$i++;
$dict.= "<<";
$offset++;
} else if (!$is_bracket && ($data[$offset] == ">") && ($data[$offset + 1] == ">")) {
$i--;
$dict.= ">>";
$offset++;
} else {
$dict.= $data[$offset];
}
$offset++;
} while ($i > 0);
If a pdf has such an object like the followings,
tcpdf_parser
fails to continue parsing the data.getRawObject()
is expected to return an array which contains an object and its offset, but it currently returns an object without its offset if the pdf has%
comments. It causes Illegal string offset warnings.PDF Object Sample
Warning Example