Skip to content

Commit

Permalink
Reset mark position after skipping past the mark limit. Any later res…
Browse files Browse the repository at this point in the history
…et will throw instead of leaving the stream in a bad/undefined state.

Previously, this would cause us to lose track of the bytes that were skipped. For PNGs, ExifInterface skips past the entire data block, which for some files can exceed the buffer limit. We would return back to the buffer location, decode the image partially and then try to load more from the wrapped stream - which would lead to a quick EOF

This is similar to what fillbuf does when we push past the mark limit.

PiperOrigin-RevId: 349315836
  • Loading branch information
sjudd authored and glide-copybara-robot committed Dec 28, 2020
1 parent 11530fd commit 2b61482
Showing 1 changed file with 8 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,14 @@ public synchronized long skip(long byteCount) throws IOException {
pos = count;
return read;
}
return read + localIn.skip(byteCount - read);

// We can't skip over the remaining bytes without exceeding the mark limit so there will be no
// way to reset to a proper position in the stream.
long skipped = localIn.skip(byteCount - read);
if (skipped > 0) {
markpos = -1;
}
return read + skipped;
}

/**
Expand Down

0 comments on commit 2b61482

Please sign in to comment.