Skip to content

Commit 497e112

Browse files
Fix potential crash in FileReader.readAsArrayBuffer on malformed data URL
When reading as ArrayBuffer, the code splits the data URL on "," and accesses index [1] without a fallback. If the native module returns a string without a comma, this results in undefined being passed to toByteArray(), causing a crash. Added nullish coalescing to default to an empty string.
1 parent 8bac1df commit 497e112

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

packages/react-native/Libraries/Blob/FileReader.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ class FileReader extends EventTarget {
8686
return;
8787
}
8888

89-
const base64 = text.split(',')[1];
89+
const base64 = text.split(',')[1] ?? '';
9090
const typedArray = toByteArray(base64);
9191

9292
this._result = typedArray.buffer;

0 commit comments

Comments
 (0)