fix(artifacts)!: keep streamed reads within descriptor ownership

Use bounded positional reads for unpacked ASAR members and borrowed Mach-O slices so destroying a stream cannot bypass its descriptor owner. Retain uncertain ASAR closes and preserve borrowed sources after cancellation.

BREAKING CHANGE: Injected ASAR unpacked handles expose fd and read instead of createReadStream.
This commit is contained in:
morluto
2026-10-11 05:17:10 +08:00
parent be6272f261
commit e0e49e9dd5
4 changed files with 170 additions and 26 deletions
+2 -2
View File
@@ -26,6 +26,7 @@ import {
sameRegularFileState,
type StableRegularFileDescriptor,
} from "../filesystem/RegularFile.js";
import { readFileHandleChunks } from "../filesystem/readFileHandleChunks.js";
/** Read-only universal Mach-O slice reader backed by native lipo metadata. */
export class MachOSliceArtifactReader implements ArtifactReader {
@@ -207,10 +208,9 @@ export class MachOSliceArtifactReader implements ArtifactReader {
"integrity",
`Mach-O slice range is outside the artifact: ${entry.path}`,
);
const sourceStream = source.handle.createReadStream({
const sourceStream = readFileHandleChunks(source.handle, {
start: offset,
end: offset + size - 1,
autoClose: false,
...(signal === undefined ? {} : { signal }),
});
const verifySource = () => this.#verifySource(source);