yandex: fix truncated files being uploaded successfully when the source ends early
Update already wrapped the source in a counting reader but never looked at the count, so a source that supplied fewer bytes than its declared size was uploaded as a chunked request, accepted by the server and reported as a success with a truncated file stored. Compare the bytes actually read against the declared size.
This commit is contained in:
committed by
Nick Craig-Wood
parent
e2352201d1
commit
1128693468
@@ -1189,6 +1189,12 @@ func (o *Object) Update(ctx context.Context, in io.Reader, src fs.ObjectInfo, op
|
||||
return err
|
||||
}
|
||||
|
||||
// Check the source supplied the number of bytes it declared
|
||||
// otherwise a truncated file would be stored as a good upload.
|
||||
if size := src.Size(); size >= 0 && int64(in1.BytesRead()) != size {
|
||||
return fmt.Errorf("expected %d bytes in input, but got %d: %w", size, in1.BytesRead(), io.ErrUnexpectedEOF)
|
||||
}
|
||||
|
||||
// Set the modTime of the uploaded file and re-read the metadata
|
||||
// so the object has the md5sum the server computed for the upload.
|
||||
//
|
||||
|
||||
Reference in New Issue
Block a user