Commit a33189c2 authored by Adrienne Walker's avatar Adrienne Walker Committed by Commit Bot

blob: properly respect max size when copying blobs

CopyFileContentsWithOffsetAndSize takes in a max size, but uses the
wrong variable to consider how much is remaining to read, and so ends up
reading the entire file (rather than limiting to size).  Because of
this, there's a size mismatch in the calling function and the blob fails
with kInvalidBlob.

This should fix some of the errors from issue 1114200.  I also see out
of memory errors, but those make more sense than this logic error.

Bug: 1114200
Change-Id: I6d8f371655e38bdd02cc89e9d524de757e1c202a
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2392987
Commit-Queue: enne <enne@chromium.org>
Reviewed-by: default avatarDaniel Murphy <dmurph@chromium.org>
Cr-Commit-Position: refs/heads/master@{#804477}
parent 97faab2c
...@@ -97,7 +97,8 @@ bool CopyFileContentsWithOffsetAndSize(base::File* infile, ...@@ -97,7 +97,8 @@ bool CopyFileContentsWithOffsetAndSize(base::File* infile,
for (;;) { for (;;) {
size_t bytes_to_read = size_t bytes_to_read =
std::min(buffer.size(), base::saturated_cast<size_t>(max_size)); std::min(buffer.size(),
base::checked_cast<size_t>(checked_max_size.ValueOrDie()));
int bytes_read = infile->ReadAtCurrentPos(buffer.data(), bytes_to_read); int bytes_read = infile->ReadAtCurrentPos(buffer.data(), bytes_to_read);
if (bytes_read < 0) if (bytes_read < 0)
return false; return false;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment