Skip to content

Commit 3db6481

Browse files
committed
Fix one more bug.
1 parent d67e1f5 commit 3db6481

File tree

1 file changed

+6
-1
lines changed
  • firebase-firestore/src/main/java/com/google/firebase/firestore/bundle

1 file changed

+6
-1
lines changed

firebase-firestore/src/main/java/com/google/firebase/firestore/bundle/BundleReader.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,14 +163,19 @@ private int indexOfOpenBracket() {
163163
private String readJsonString(int bytesToRead) throws IOException {
164164
ByteArrayOutputStream jsonBytes = new ByteArrayOutputStream();
165165

166+
// Read at least `bytesToRead` number of bytes from the bundle into `this.buffer`, pulling more
167+
// data if necessary.
168+
// Exactly `bytesToRead` number of bytes will be put in `jsonBytes` after the loop completes.
166169
int remaining = bytesToRead;
167170
while (remaining > 0) {
168171
if (buffer.remaining() == 0 && !pullMoreData()) {
169172
throw abort("Reached the end of bundle when more data was expected.");
170173
}
171174

175+
// `read` is the number of bytes guaranteed to exist in `this.buffer` after the above
176+
// call to `pullMoreData`. Copy them to `jsonBytes` and advance `this.buffer`'s position.
172177
int read = Math.min(remaining, buffer.remaining());
173-
jsonBytes.write(buffer.slice().array(), 0, read);
178+
jsonBytes.write(buffer.array(), buffer.position(), read);
174179
buffer.position(buffer.position() + read);
175180

176181
remaining -= read;

0 commit comments

Comments
 (0)