libmergepdf icon indicating copy to clipboard operation
libmergepdf copied to clipboard

Uninitialized string offset: 548

Open Hecke29 opened this issue 4 years ago • 3 comments

When I try to merge PDFs with the following code I get the error Notice: Uninitialized string offset: 548

$merger = new Merger(new TcpdiDriver());
$merger->addIterator([new File('354025a5-original.pdf', true), new File('another.pdf', true)]);
$mergedPdf = $merger->merge();

This happens when trying to merge the attached PDF File 354025a5-original.pdf

More stack:

Notice: Uninitialized string offset: 548
--
in tcpdi_parser.php line 711
at tcpdi_parser->getRawObject(548, '/NumberofPages 1/PageWidthList<</0 841.89>>/DocumentID<FEFF0078006D0070002E006400690064003A00360065006500660036006600380036002D0030003000300035002D0034003700620063002D0061003000350031002D003600330030003500640065003300300061003100650034>/OriginalDocumentID<FEFF0078006D0070002E006400690064003A00620065006200360061003800380062002D0030003100640063002D0034003200330038002D0039003300350037002D006300370036006300360037003400300062003200660030>/PageUIDList<</0 3650>>/LastModified<FEFF0044003A00320030003100390031003200310038003100300030003500330036005A>>')in tcpdi_parser.php line 916
at tcpdi_parser->getDictValue(559, '/InDesign<</NumberofPages 1/PageWidthList<</0 841.89>>/DocumentID<FEFF0078006D0070002E006400690064003A00360065006500660036006600380036002D0030003000300035002D0034003700620063002D0061003000350031002D003600330030003500640065003300300061003100650034>/OriginalDocumentID<FEFF0078006D0070002E006400690064003A00620065006200360061003800380062002D0030003100640063002D0034003200330038002D0039003300350037002D006300370036006300360037003400300062003200660030>/PageUIDList<</0 3650>>/LastModified<FEFF0044003A00320030003100390031003200310038003100300030003500330036005A>>>>')in tcpdi_parser.php line 798
at tcpdi_parser->getRawObject(9, '/InDesign<</NumberofPages 1/PageWidthList<</0 841.89>>/DocumentID<FEFF0078006D0070002E006400690064003A00360065006500660036006600380036002D0030003000300035002D0034003700620063002D0061003000350031002D003600330030003500640065003300300061003100650034>/OriginalDocumentID<FEFF0078006D0070002E006400690064003A00620065006200360061003800380062002D0030003100640063002D0034003200330038002D0039003300350037002D006300370036006300360037003400300062003200660030>/PageUIDList<</0 3650>>/LastModified<FEFF0044003A00320030003100390031003200310038003100300030003500330036005A>>>>')in tcpdi_parser.php line 916
at tcpdi_parser->getDictValue(848, '/BleedBox[ 0 0 841.89 595.276]/Resources<</ColorSpace<</CS0 8 0 R >>/XObject<</Im0 10 0 R >>/ExtGState<</GS0 9 0 R >>/ProcSet[/PDF/ImageC/ImageI]>>/MediaBox[ 0 0 841.89 595.276]/TrimBox[ 0 0 841.89 595.276]/Type/Page/Parent 3 0 R /Contents 7 0 R /CropBox[ 0 0 841.89 595.276]/PieceInfo<</InDesign<</NumberofPages 1/PageWidthList<</0 841.89>>/DocumentID<FEFF0078006D0070002E006400690064003A00360065006500660036006600380036002D0030003000300035002D0034003700620063002D0061003000350031002D003600330030003500640065003300300061003100650034>/OriginalDocumentID<FEFF0078006D0070002E006400690064003A00620065006200360061003800380062002D0030003100640063002D0034003200330038002D0039003300350037002D006300370036006300360037003400300062003200660030>/PageUIDList<</0 3650>>/LastModified<FEFF0044003A00320030003100390031003200310038003100300030003500330036005A>>>>>>')in tcpdi_parser.php line 798
at tcpdi_parser->getRawObject(285, '/BleedBox[ 0 0 841.89 595.276]/Resources<</ColorSpace<</CS0 8 0 R >>/XObject<</Im0 10 0 R >>/ExtGState<</GS0 9 0 R >>/ProcSet[/PDF/ImageC/ImageI]>>/MediaBox[ 0 0 841.89 595.276]/TrimBox[ 0 0 841.89 595.276]/Type/Page/Parent 3 0 R /Contents 7 0 R /CropBox[ 0 0 841.89 595.276]/PieceInfo<</InDesign<</NumberofPages 1/PageWidthList<</0 841.89>>/DocumentID<FEFF0078006D0070002E006400690064003A00360065006500660036006600380036002D0030003000300035002D0034003700620063002D0061003000350031002D003600330030003500640065003300300061003100650034>/OriginalDocumentID<FEFF0078006D0070002E006400690064003A00620065006200360061003800380062002D0030003100640063002D0034003200330038002D0039003300350037002D006300370036006300360037003400300062003200660030>/PageUIDList<</0 3650>>/LastModified<FEFF0044003A00320030003100390031003200310038003100300030003500330036005A>>>>>>')in tcpdi_parser.php line 916
...

Even more stack available if necessary. How can I challenge this problem? Is that tcpdi_parser even maintained by you?

Hecke29 avatar Jan 08 '20 00:01 Hecke29

An dirty

        while (!isset($data{$offset})) {
            $offset-=2;
        }

in tcpdi_parser works. Will look into how to make this "cleaner".

Hecke29 avatar Jan 08 '20 00:01 Hecke29

Hi! And thanx for reporting!

No I'm not maintaining it actually. I put it in the source because no one seems to be maintaining anything and I needed to make some minor fixes for php 7.4.. If you have found a more official version that works I'm happy to use that instead. Otherwise I'll merge any fix as long as there are some additional tests. I can write an acceptance test with your failing file if you want something to hack against..

hanneskod avatar Jan 13 '20 14:01 hanneskod

I'm havig this same issue in some cases of merge.

I removed the try/catch statement to see where it came from.

Uninitialized string offset: 22 {"userId":1,"exception":"\[object\] (ErrorException(code: 0): Uninitialized string offset: 22 at .../vendor/iio/libmergepdf/tcpdi/tcpdi_parser.php:711)

guianzollin avatar Oct 28 '22 19:10 guianzollin