From 781991b6bf935aef80ae7a6ba3931b2bd62be0ab Mon Sep 17 00:00:00 2001 From: EliotJones Date: Sun, 6 Jul 2025 17:56:59 -0500 Subject: [PATCH] fix #670 by ignoring duplicate endstream definitions when parsing a stream object with multiple endstream tokens the last parsed token was selected instead of the actual stream token so instead we just skip all following tokens if the first is a stream and the following tokens are `endstream` operators only --- src/UglyToad.PdfPig/Tokenization/Scanner/PdfTokenScanner.cs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/UglyToad.PdfPig/Tokenization/Scanner/PdfTokenScanner.cs b/src/UglyToad.PdfPig/Tokenization/Scanner/PdfTokenScanner.cs index 4bfd802d..e9e408fd 100644 --- a/src/UglyToad.PdfPig/Tokenization/Scanner/PdfTokenScanner.cs +++ b/src/UglyToad.PdfPig/Tokenization/Scanner/PdfTokenScanner.cs @@ -268,6 +268,12 @@ { token = trimmedDuplicatedEndTokens[0]; } + else if (readTokens[0] is StreamToken str + && readTokens.Skip(1).All(x => x is OperatorToken op && op.Equals(OperatorToken.EndStream))) + { + // If a stream token is followed by "endstream" operator tokens just skip the following duplicated tokens. + token = str; + } else { token = readTokens[readTokens.Count - 1];