Open
Conversation
romanpickl
reviewed
Mar 12, 2024
read.go
Outdated
| buf := make([]byte, 10) | ||
| f.ReadAt(buf, 0) | ||
| if !bytes.HasPrefix(buf, []byte("%PDF-1.")) || buf[7] < '0' || buf[7] > '7' || buf[8] != '\r' && buf[8] != '\n' { | ||
| if !bytes.HasPrefix(buf, []byte("%PDF-1.")) || buf[7] < '0' || buf[7] > '7' || buf[8] != '\r' || buf[8] != '\n' { |
This comment was marked as outdated.
This comment was marked as outdated.
Sorry, something went wrong.
This comment was marked as outdated.
This comment was marked as outdated.
Sorry, something went wrong.
romanpickl
reviewed
Mar 12, 2024
| func NewReaderEncrypted(f io.ReaderAt, size int64, pw func() string) (*Reader, error) { | ||
| buf := make([]byte, 10) | ||
| const headerLen = 11 | ||
| buf := make([]byte, 11) |
There was a problem hiding this comment.
use headerLen otherwise delete const?
romanpickl
reviewed
Mar 12, 2024
| // headerRegexp is used to check the validity of the header line of a PDF. | ||
| // This should be able to support extra spaces between the version and the | ||
| // newline (as inserted by libtiff/tiff2pdf) as well as supporting CRLF and LF. | ||
| var headerRegexp = regexp.MustCompile(`^%PDF-1\.[0-7]\s*\r?\n`) |
There was a problem hiding this comment.
i think %PDF-1.7\r
is a valid case as well.
There was a problem hiding this comment.
in my tests i changed this to
^%PDF-1\.[0-7][ ]*[\r\n]+
need to check the spec again.
Owner
|
@lzambarda can you fix @romanpickl comment, Otherwise looks good |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Hey there! This is probably too big as a single PR, but some changes can be cherry-picked for the benefit of the project!
a962e84 addresses issue #22 . The previous header check logic was too strict and also had a bug (7dfab7e)
Some other changes are also to address #20 which seems to be a limitation in the current implementation. I left a comment in the code but also adding here the original resource which made me appyl the change: https://stackoverflow.com/questions/11896858/does-the-eof-in-a-pdf-have-to-appear-within-the-last-1024-bytes-of-the-file
In e3c03b5 I fixed a bug not correctly surfacing panics as errors inside the library.
I have also added a
go.modfile to pleasereplace.Hope this can help!