Blob#slice end <= size (fixes #35959) (#35971)

Summary:
See https://github.com/facebook/react-native/issues/35959 .  Potentially fixes other issues including https://github.com/facebook/react-native/issues/34988

## Changelog

[INTERNAL] [FIXED] - Blob#slice end check avoids overflow

Pull Request resolved: https://github.com/facebook/react-native/pull/35971

Test Plan: Added a test which fails against current release but passes after code changes.

Reviewed By: cipolleschi

Differential Revision: D42772352

Pulled By: jacdebug

fbshipit-source-id: 3c26baedad5cd459061459a9485ae20af1d2417b
This commit is contained in:
SheetJS
2023-01-27 01:36:57 -08:00
committed by Facebook GitHub Bot
parent d30bd1bb21
commit eaf465d0df
2 changed files with 9 additions and 0 deletions
+4
View File
@@ -98,6 +98,10 @@ class Blob {
// $FlowFixMe[reassign-const]
end = this.size + end;
}
if (end > this.size) {
// $FlowFixMe[reassign-const]
end = this.size;
}
size = end - start;
}
}
+5
View File
@@ -71,6 +71,11 @@ describe('Blob', function () {
expect(sliceB.data.offset).toBe(2384);
expect(sliceB.size).toBe(7621 - 2384);
expect(sliceB.type).toBe('');
const sliceC = blob.slice(34543, 34569);
expect(sliceC.data.offset).toBe(34543);
expect(sliceC.size).toBe(Math.min(blob.data.size, 34569) - 34543);
});
it('should close a blob', () => {