Skip to content

[Bug] buffer expansion bug in yy_refill()? [sf#60] #62

@lsf37

Description

@lsf37

Reported by smagoun on 2004-01-30 20:35 UTC
yy_refill() in skeleton.default and skeleton.nested seems to
have a problem expanding the buffer correctly. The bug
manifests itself when reading a lot of data at once. I ran into
this using the Piccolo XML parser, which uses JFlex to parse
XML. Piccolo died while reading a very long CDATA element
in the XML. I tracked it to yy_refill(), which seems to have
been copied from one of the skeleton files JFlex ships with.

The problem is that the buffer never expands properly when
reading long input, which results in an
ArrayIndexOutOfBoundsException. The following patch fixes
Piccolo; I'm not sure if it applies to JFlex, but I'm guessing it
might.

(I'm not convinced that the if() should check
yy_currentPos>=buffer.length at all, but it seems harmless)

--- PiccoloLexer.java   Sun Jul  7 14:21:18 2002
+++ PiccoloLexer copy.java      Fri Jan 30 15:07:44 2004
@@ -3291,9 +3291,10 @@
}

/* is the buffer big enough? */
-    if (yy_currentPos >= yy_buffer.length) {
+    if (yy_currentPos >= yy_buffer.length)
+        || yy_markedPos >= yy_buffer.length) {
/* if not: blow it up */
-      char newBuffer[] = new char[yy_currentPos*2];
+      char newBuffer[] = new char[yy_buffer.length*2];
System.arraycopy(yy_buffer, 0, newBuffer, 0, 
yy_buffer.length);
yy_buffer = newBuffer;
}

Metadata

Metadata

Assignees

Labels

bugNot working as intended

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions