From a27c6bbf900dae9f15fe05aa6e5e9aed8541ada4 Mon Sep 17 00:00:00 2001 From: Peter Williams Date: Mon, 1 Oct 2018 16:47:09 +1000 Subject: [PATCH] Hack to suppress EOF errors when parsing PDF fragments in font_test.go --- pdf/core/parser.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/pdf/core/parser.go b/pdf/core/parser.go index 20d7d43d..6a194c49 100644 --- a/pdf/core/parser.go +++ b/pdf/core/parser.go @@ -52,6 +52,9 @@ type PdfParser struct { // the length reference (if not object) prior to reading the actual stream. This has risks of endless looping. // Tracking is necessary to avoid recursive loops. streamLengthReferenceLookupInProgress map[int64]bool + + // Hack to allow parsing of PDF fragments without reporting an EOF error. + suppressEOF bool } // PdfVersion returns version of the PDF file. @@ -1322,7 +1325,9 @@ func (parser *PdfParser) ParseIndirectObject() (PdfObject, error) { common.Log.Trace("-Read indirect obj") bb, err := parser.reader.Peek(20) if err != nil { - common.Log.Debug("ERROR: Fail to read indirect obj") + if !(parser.suppressEOF && err == io.EOF) { + common.Log.Debug("ERROR: Fail to read indirect obj. err=%v", err) + } return &indirect, err } common.Log.Trace("(indirect obj peek \"%s\"", string(bb)) @@ -1493,7 +1498,7 @@ func (parser *PdfParser) ParseIndirectObject() (PdfObject, error) { // For testing purposes. // TODO: Unexport (v3) or move to test files, if needed by external test cases. func NewParserFromString(txt string) *PdfParser { - parser := PdfParser{} + parser := PdfParser{suppressEOF: true} buf := []byte(txt) bufReader := bytes.NewReader(buf)