From 161b4babe861a9fcd386d2d7ba5636aa3cedf9cc Mon Sep 17 00:00:00 2001 From: Jesse Wilson Date: Fri, 22 Jul 2011 15:50:26 +0000 Subject: [PATCH] Fix a pair of relatively benign off-by-one bugs. These only manifest if the source Reader returns characters one-at-a-time. --- gson/src/main/java/com/google/gson/stream/JsonReader.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/gson/src/main/java/com/google/gson/stream/JsonReader.java b/gson/src/main/java/com/google/gson/stream/JsonReader.java index 6eb360c2..2719c8e1 100644 --- a/gson/src/main/java/com/google/gson/stream/JsonReader.java +++ b/gson/src/main/java/com/google/gson/stream/JsonReader.java @@ -846,7 +846,7 @@ public final class JsonReader implements Closeable { limit += total; // if this is the first read, consume an optional byte order mark (BOM) if it exists - if (bufferStartLine == 1 && bufferStartColumn == 1 && limit > 1 && buffer[0] == '\ufeff') { + if (bufferStartLine == 1 && bufferStartColumn == 1 && limit > 0 && buffer[0] == '\ufeff') { pos++; bufferStartColumn--; } @@ -956,7 +956,7 @@ public final class JsonReader implements Closeable { private boolean skipTo(String toFind) throws IOException { outer: - for (; pos + toFind.length() < limit || fillBuffer(toFind.length()); pos++) { + for (; pos + toFind.length() <= limit || fillBuffer(toFind.length()); pos++) { for (int c = 0; c < toFind.length(); c++) { if (buffer[pos + c] != toFind.charAt(c)) { continue outer;