Skip to content

Commit 4344b6a

Browse files
committed
fix(lib-storage): restrict lstat calls to fs.ReadStream objects
1 parent bc9d888 commit 4344b6a

File tree

3 files changed

+8
-3
lines changed

3 files changed

+8
-3
lines changed

lib/lib-storage/src/byteLength.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,7 @@ export const byteLength = (input: any): number | undefined => {
2929
} else if (typeof input.start === "number" && typeof input.end === "number") {
3030
// file read stream with range.
3131
return input.end + 1 - input.start;
32-
} else if (typeof input.path === "string") {
33-
// file read stream with path.
32+
} else if (runtimeConfig.isFileReadStream(input)) {
3433
try {
3534
return runtimeConfig.lstatSync(input.path).size;
3635
} catch (error) {

lib/lib-storage/src/runtimeConfig.shared.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,7 @@
33
*/
44
export const runtimeConfigShared = {
55
lstatSync: () => {},
6+
isFileReadStream(f: unknown) {
7+
return false;
8+
},
69
};

lib/lib-storage/src/runtimeConfig.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { lstatSync } from "fs";
1+
import { lstatSync, ReadStream } from "fs";
22

33
import { runtimeConfigShared as shared } from "./runtimeConfig.shared";
44

@@ -9,4 +9,7 @@ export const runtimeConfig = {
99
...shared,
1010
runtime: "node",
1111
lstatSync,
12+
isFileReadStream(f: unknown): f is ReadStream {
13+
return f instanceof ReadStream;
14+
},
1215
};

0 commit comments

Comments
 (0)