From eaf465d0df2ba0d03bea97a7b5e2d9f65afca2ca Mon Sep 17 00:00:00 2001 From: SheetJS Date: Fri, 27 Jan 2023 01:36:57 -0800 Subject: [PATCH] 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 --- Libraries/Blob/Blob.js | 4 ++++ Libraries/Blob/__tests__/Blob-test.js | 5 +++++ 2 files changed, 9 insertions(+) diff --git a/Libraries/Blob/Blob.js b/Libraries/Blob/Blob.js index 862c3f50bdcb0f..a75fb1b3688a16 100644 --- a/Libraries/Blob/Blob.js +++ b/Libraries/Blob/Blob.js @@ -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; } } diff --git a/Libraries/Blob/__tests__/Blob-test.js b/Libraries/Blob/__tests__/Blob-test.js index 9fdabab67ef530..e5308c0d2c5811 100644 --- a/Libraries/Blob/__tests__/Blob-test.js +++ b/Libraries/Blob/__tests__/Blob-test.js @@ -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', () => {