Skip to content

Commit ea9988f

Browse files
authored
Merge pull request #256 from unidoc/development
Apply fixes to master
2 parents 97286a4 + 84f80af commit ea9988f

File tree

3 files changed

+77
-1
lines changed

3 files changed

+77
-1
lines changed

contentstream/inline-image.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -411,6 +411,12 @@ func (csp *ContentStreamParser) ParseInlineImage() (*ContentStreamInlineImage, e
411411
skipBytes = []byte{}
412412
skipBytes = append(skipBytes, c)
413413
state = 1
414+
} else if c == 'E' {
415+
// Allow cases where EI is not preceded by whitespace.
416+
// The extra parsing after EI<ws> should be sufficient
417+
// in order to decide if the image stream ended.
418+
skipBytes = append(skipBytes, c)
419+
state = 2
414420
} else {
415421
im.stream = append(im.stream, c)
416422
}

core/parser.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1137,7 +1137,7 @@ func (parser *PdfParser) seekToEOFMarker(fSize int64) error {
11371137
// Define an buffer length in terms of how many bytes to read from the end of the file.
11381138
var buflen int64 = 2048
11391139

1140-
for offset < fSize {
1140+
for offset < fSize-4 {
11411141
if fSize <= (buflen + offset) {
11421142
buflen = fSize - offset
11431143
}

core/parser_test.go

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -479,6 +479,76 @@ func TestStreamParsing(t *testing.T) {
479479
// TODO
480480
}
481481

482+
func TestEOFParsing(t *testing.T) {
483+
testcases := []struct {
484+
Min int
485+
Increment int
486+
Max int
487+
Suffix string
488+
ShouldErr bool
489+
}{
490+
{
491+
Min: 0,
492+
Increment: 1,
493+
Max: 30,
494+
Suffix: "",
495+
ShouldErr: true,
496+
},
497+
{
498+
Min: 0,
499+
Increment: 1,
500+
Max: 30,
501+
Suffix: "%%EOF",
502+
ShouldErr: false,
503+
},
504+
{
505+
Min: 0,
506+
Increment: 1,
507+
Max: 30,
508+
Suffix: "%%EOF\n",
509+
ShouldErr: false,
510+
},
511+
{
512+
Min: 0,
513+
Increment: 1,
514+
Max: 30,
515+
Suffix: "%EOF\n",
516+
ShouldErr: true,
517+
},
518+
{
519+
Min: 1010,
520+
Increment: 1,
521+
Max: 1040,
522+
Suffix: "%%EOF\n",
523+
ShouldErr: false,
524+
},
525+
{
526+
Min: 2000,
527+
Increment: 1,
528+
Max: 2040,
529+
Suffix: "%%EOF",
530+
ShouldErr: false,
531+
},
532+
}
533+
for _, tcase := range testcases {
534+
for i := tcase.Min; i < tcase.Max; i += tcase.Increment {
535+
b := make([]byte, i)
536+
for j := 0; j < i; j++ {
537+
b[j] = ' '
538+
}
539+
b = append(b, []byte(tcase.Suffix)...)
540+
541+
parser := makeParserForText(string(b))
542+
err := parser.seekToEOFMarker(int64(len(b)))
543+
if tcase.ShouldErr {
544+
require.NotNil(t, err)
545+
} else {
546+
require.NoError(t, err)
547+
}
548+
}
549+
}
550+
}
551+
482552
func TestIndirectObjParsing1(t *testing.T) {
483553
testcases := []struct {
484554
description string

0 commit comments

Comments
 (0)