Skip to content

More flexible logic for libtiff#25

Open
lzambarda wants to merge 6 commits intoledongthuc:masterfrom
lzambarda:master
Open

More flexible logic for libtiff#25
lzambarda wants to merge 6 commits intoledongthuc:masterfrom
lzambarda:master

Conversation

@lzambarda
Copy link

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 please replace.
Hope this can help!

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.

func NewReaderEncrypted(f io.ReaderAt, size int64, pw func() string) (*Reader, error) {
buf := make([]byte, 10)
const headerLen = 11
buf := make([]byte, 11)
Copy link

@romanpickl romanpickl Mar 12, 2024

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`)
Copy link

@romanpickl romanpickl Mar 12, 2024

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.

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.

@ledongthuc
Copy link
Owner

@lzambarda can you fix @romanpickl comment, Otherwise looks good

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants