-
Notifications
You must be signed in to change notification settings - Fork 150
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
More flexible logic for libtiff #25
base: master
Are you sure you want to change the base?
Conversation
read.go
Outdated
@@ -129,7 +129,7 @@ func NewReader(f io.ReaderAt, size int64) (*Reader, error) { | |||
func NewReaderEncrypted(f io.ReaderAt, size int64, pw func() string) (*Reader, error) { | |||
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.
// NewReaderEncrypted opens a file for reading, using the data in f with the given total size. | ||
// If the PDF is encrypted, NewReaderEncrypted calls pw repeatedly to obtain passwords | ||
// to try. If pw returns the empty string, NewReaderEncrypted stops trying to decrypt | ||
// the file and returns an error. | ||
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use headerLen otherwise delete const?
// 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i think %PDF-1.7\r
is a valid case as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
in my tests i changed this to
^%PDF-1\.[0-7][ ]*[\r\n]+
need to check the spec again.
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.mod
file to pleasereplace
.Hope this can help!