From 51caa038a9c9e4a3da4d826685e05200589182e4 Mon Sep 17 00:00:00 2001 From: Jonas Konrad Date: Wed, 23 Nov 2022 13:00:20 +0100 Subject: [PATCH] Fix TOML parse failure when number token hits buffer edge (#95) When a number token is exactly at the end of the lexer text buffer, the parser would advance the lexer, triggering a buffer refill, before the number is parsed from the buffer. This patch moves the advance operation to come after parsing, which resolves the issue. Also tracked as https://github.com/FasterXML/jackson-dataformats-text/pull/356 Fixes #93 Co-authored-by: Tim Yates --- toml/src/main/java/io/micronaut/toml/Parser.java | 5 +++++ toml/src/test/java/io/micronaut/toml/ParserTest.java | 10 ++++++++++ 2 files changed, 15 insertions(+) diff --git a/toml/src/main/java/io/micronaut/toml/Parser.java b/toml/src/main/java/io/micronaut/toml/Parser.java index 814bf59e..db2a2b36 100644 --- a/toml/src/main/java/io/micronaut/toml/Parser.java +++ b/toml/src/main/java/io/micronaut/toml/Parser.java @@ -256,7 +256,12 @@ private JsonNode parseInt(int nextState) throws IOException { } } + JsonNode v = parseInt0(buffer, start, length); pollExpected(TomlToken.INTEGER, nextState); + return v; + } + + private JsonNode parseInt0(char[] buffer, int start, int length) throws TomlStreamReadException { if (length > 2) { char baseChar = buffer[start + 1]; if (baseChar == 'x' || baseChar == 'o' || baseChar == 'b') { diff --git a/toml/src/test/java/io/micronaut/toml/ParserTest.java b/toml/src/test/java/io/micronaut/toml/ParserTest.java index dcb68e4e..1496b27a 100644 --- a/toml/src/test/java/io/micronaut/toml/ParserTest.java +++ b/toml/src/test/java/io/micronaut/toml/ParserTest.java @@ -1016,4 +1016,14 @@ public void unknownEscape() throws IOException { Assertions.assertThrows(TomlStreamReadException.class, () -> toml("foo = \"\\k\"")).getOriginalMessage(), Matchers.containsString("Unknown escape sequence")); } + + @Test + // https://github.com/micronaut-projects/micronaut-toml/pull/95 + void longInput() { + Assertions.assertDoesNotThrow(() -> toml( + "foo = \"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\"\n" + + "bar = 678\n" + + "baz = \"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\"" + )); + } }