8000 Apply fixes to master by gunnsth · Pull Request #256 · unidoc/unipdf · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Apply fixes to master #256

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

Merged
merged 5 commits into from
Feb 12, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions contentstream/inline-image.go
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,12 @@ func (csp *ContentStreamParser) ParseInlineImage() (*ContentStreamInlineImage, e
skipBytes = []byte{}
skipBytes = append(skipBytes, c)
state = 1
} else if c == 'E' {
// Allow cases where EI is not preceded by whitespace.
// The extra parsing after EI<ws> should be sufficient
// in order to decide if the image stream ended.
skipBytes = append(skipBytes, c)
state = 2
} else {
im.stream = append(im.stream, c)
}
Expand Down
2 changes: 1 addition & 1 deletion core/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -1137,7 +1137,7 @@ func (parser *PdfParser) seekToEOFMarker(fSize int64) error {
// Define an buffer length in terms of how many bytes to read from the end of the file.
var buflen int64 = 2048

for offset < fSize {
for offset < fSize-4 {
if fSize <= (buflen + offset) {
buflen = fSize - offset
}
Expand Down
70 changes: 70 additions & 0 deletions core/parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -479,6 +479,76 @@ func TestStreamParsing(t *testing.T) {
// TODO
}

func TestEOFParsing(t *testing.T) {
testcases := []struct {
Min int
Increment int
Max int
Suffix string
ShouldErr bool
}{
{
Min: 0,
Increment: 1,
Max: 30,
Suffix: "",
ShouldErr: true,
},
{
Min: 0,
Increment: 1,
Max: 30,
Suffix: "%%EOF",
ShouldErr: false,
},
{
Min: 0,
Increment: 1,
Max: 30,
Suffix: "%%EOF\n",
ShouldErr: false,
},
{
Min: 0,
Increment: 1,
Max: 30,
Suffix: "%EOF\n",
ShouldErr: true,
},
{
Min: 1010,
Increment: 1,
Max: 1040,
Suffix: "%%EOF\n",
ShouldErr: false,
},
{
Min: 2000,
Increment: 1,
Max: 2040,
Suffix: "%%EOF",
ShouldErr: false,
},
}
for _, tcase := range testcases {
for i := tcase.Min; i < tcase.Max; i += tcase.Increment {
b := make([]byte, i)
for j := 0; j < i; j++ {
b[j] = ' '
}
b = append(b, []byte(tcase.Suffix)...)

parser := makeParserForText(string(b))
err := parser.seekToEOFMarker(int64(len(b)))
if tcase.ShouldErr {
require.NotNil(t, err)
} else {
require.NoError(t, err)
}
}
}
}

func TestIndirectObjParsing1(t *testing.T) {
testcases := []struct {
description string
Expand Down
31A9
0