dealfonso / sapp

Simple and Agnostic PDF Document Parser in PHP - sign PDF docs using PHP
GNU Lesser General Public License v3.0
115 stars 30 forks source link

Parsing previously signed PDF throws "Invalid token" exception in Parser #17

Closed micah1701 closed 2 years ago

micah1701 commented 2 years ago

admittedly, I do not fully understand the underlying object structure of PDF, so feel free to take my "issue" with a grain of salt. I created a signed (with image) PDF, based on the pdfsigni.php example. It worked and I was able to generate a signed PDF. Very cool, I might add!

However, when I attempt to run the same script on the newly generated PDF, it dies out on line 350 of the PDFObjectParser (which is the default switch case when there is an invalid token.) For what its worth, my "Invalid token" (eg $this->_tt) is "5." I don't really know what that means though, LOL

Any thoughts on what silly and obvious thing I am missing here? Thanks!

dealfonso commented 2 years ago

Hi,

thank you for reporting. It would be nice if you could provide an example of this error. It seems that it has to do with issue #10

micah1701 commented 2 years ago

Thanks for your quick reply. I did a little bit more testing and, using your examples/testdoc.pdf worked fine without the given error so, there is presumably something wonky about my source PDF.

Here's my test repo: https://github.com/micah1701/sapp

This works: in myapp/index.php when using the source document "examples/testdoc.pdf" I am able to create a signed pdf and save it to "files/testdoc1.pdf" I then change the source document to files/testdoc1.pdf" and am able to create a second signed pdf, and save it to "files/testdoc2.pdf"

This also works: in myapp/test.php (which is a clone of index.php) using the source document "examples/LAB.pdf" I am able to create a signed pdf and save it to "files/LAB1.pdf"

BUT: when I change the source document to files/LAB1.pdf (the signed version of my example pdf) and attempt to create a second signed PDF, that is when I get the previously mentioned error.

EDIT: I do realize a fatal flaw in my testing that may, in fact, make this issue moot. I'm signing a document, and then modifying it with another image of a signature and signing it again....which in the laws of PDF breaks the first first signature. This is evedent in my "working" test using the testdoc.pdf where, if you view testdoc2.pdf the signature isn't valid. Regardless of this logic flaw, the issue does still stand that it sorta works with the tesdoc.pdf but throws the token issue using my LAB.pdf document. Weirdness.

dealfonso commented 2 years ago

Hi, I have just updated the code to support escaped parenthesis in the strings (which seemed to be related to your problem and issue #10). Could you please test this version?

micah1701 commented 2 years ago

That absolutely worked! Thank you for taking the time to maintain this valuable repo. Cheers