Skip to content

Commit d25290f

Browse files
committed
fix: Use safe check for ArrayBufferLike.
1 parent ab45be6 commit d25290f

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

src/decode/decode-ipc.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
* @import { ArrowData, Version_ } from '../types.js'
33
*/
44
import { MAGIC, MessageHeader, Version } from '../constants.js';
5+
import { isArrayBufferLike } from '../util/arrays.js';
56
import { readInt16, readInt32, readObject } from '../util/read.js';
67
import { decodeBlocks } from './block.js';
78
import { decodeMessage } from './message.js';
@@ -25,9 +26,7 @@ import { decodeSchema } from './schema.js';
2526
* @returns {import('../types.js').ArrowData}
2627
*/
2728
export function decodeIPC(data) {
28-
const source = data instanceof ArrayBuffer || data instanceof SharedArrayBuffer
29-
? new Uint8Array(data)
30-
: data;
29+
const source = isArrayBufferLike(data) ? new Uint8Array(data) : data;
3130
return source instanceof Uint8Array && isArrowFileFormat(source)
3231
? decodeIPCFile(source)
3332
: decodeIPCStream(source);

src/util/arrays.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,18 @@ export const int64Array = BigInt64Array;
1212
export const float32Array = Float32Array;
1313
export const float64Array = Float64Array;
1414

15+
/**
16+
* Check if an input value is an ArrayBuffer or SharedArrayBuffer.
17+
* @param {unknown} data
18+
* @returns {data is ArrayBufferLike}
19+
*/
20+
export function isArrayBufferLike(data) {
21+
return data instanceof ArrayBuffer || (
22+
typeof SharedArrayBuffer !== 'undefined' &&
23+
data instanceof SharedArrayBuffer
24+
);
25+
}
26+
1527
/**
1628
* Return the appropriate typed array constructor for the given
1729
* integer type metadata.

0 commit comments

Comments
 (0)