<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">From 2622dbb98404d72667734c85d23a1f9da4cfc941 Mon Sep 17 00:00:00 2001
From: Adam Sampson &lt;ats@offog.org&gt;
Date: Fri, 11 Jul 2025 04:45:39 +0100
Subject: [PATCH 1/1] Update turtle_parser-&gt;consumed on the last chunk

When it's not the last chunk, any data that hasn't been consumed is
moved to the start of the buffer, and -&gt;consumed is set to the length.
However, -&gt;consumed wasn't being reset for the last chunk - so if you
reused a turtle parser after feeding a last chunk through it, the state
would be inconsistent: the next chunk would get copied after the data
from the previous chunk, but the parser would read from the start of the
buffer...

To fix this, just set -&gt;consumed to 0 after the last chunk, so the
buffer gets cleared.

This fixes a failure in librdf's rdf_parser test, which feeds several
strings through the same parser: the "Adding turtle counted string" test
produces "librdf error XXX - syntax error at XXX" with XXX being binary
garbage as the parser ran off the end of the buffer.
---
 src/turtle_parser.y | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/src/turtle_parser.y b/src/turtle_parser.y
index f9602638..bf970eb5 100644
--- a/src/turtle_parser.y
+++ b/src/turtle_parser.y
@@ -1774,7 +1774,8 @@ raptor_turtle_parse_chunk(raptor_parser* rdf_parser,
       }
     }
   } else {
-    /* this was the last chunk, finalise */
+    /* this was the last chunk, empty the buffer and finalise */
+    turtle_parser-&gt;consumed = 0;
     if(turtle_parser-&gt;deferred) {
       raptor_sequence* def = turtle_parser-&gt;deferred;
       int i;
-- 
2.50.1

And the output from yacc:

--- raptor2-2.0.16/src/turtle_parser.c	2021-11-28 05:01:03.000000000 +0000
+++ raptor2-2.0.16/src/turtle_parser.c	2025-07-11 05:10:41.614692852 +0100
@@ -3675,7 +3675,8 @@
       }
     }
   } else {
-    /* this was the last chunk, finalise */
+    /* this was the last chunk, empty the buffer and finalise */
+    turtle_parser-&gt;consumed = 0;
     if(turtle_parser-&gt;deferred) {
       raptor_sequence* def = turtle_parser-&gt;deferred;
       int i;
</pre></body></html>