mirror of
https://github.com/morluto/rea
synced 2026-10-26 06:16:17 -04:00
refactor(apple): reuse artifact stream byte validation
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import { createHash } from "node:crypto";
|
||||
import { lstat } from "node:fs/promises";
|
||||
import { streamChunkToBuffer } from "../StreamBytes.js";
|
||||
import { DirectoryArtifactReader } from "../DirectoryArtifactReader.js";
|
||||
import { ArtifactTraversalObservation } from "../ArtifactTraversalObservation.js";
|
||||
import {
|
||||
@@ -353,7 +354,7 @@ const digestBounded = async (
|
||||
"Asset catalog inspection cancelled",
|
||||
{ cause: signal.reason },
|
||||
);
|
||||
const bytes = Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk);
|
||||
const bytes = streamChunkToBuffer(chunk);
|
||||
length += bytes.length;
|
||||
if (length > MAX_CATALOG_BYTES)
|
||||
throw new ArtifactReaderFailure(
|
||||
|
||||
@@ -8,6 +8,7 @@ import {
|
||||
isSourceLessAppKitAnnotationConnector,
|
||||
isUIKitRuntimeConnectionClass,
|
||||
} from "../../domain/apple/interfaceBuilderKeyedArchive.js";
|
||||
import { streamChunkToBuffer } from "../StreamBytes.js";
|
||||
import { DirectoryArtifactReader } from "../DirectoryArtifactReader.js";
|
||||
import { ArtifactTraversalObservation } from "../ArtifactTraversalObservation.js";
|
||||
import {
|
||||
@@ -861,9 +862,7 @@ const readEntry = async (
|
||||
const chunks: Buffer[] = [];
|
||||
let length = 0;
|
||||
for await (const chunk of stream) {
|
||||
const bytes = Buffer.isBuffer(chunk)
|
||||
? chunk
|
||||
: Buffer.from(chunk as Uint8Array);
|
||||
const bytes = streamChunkToBuffer(chunk);
|
||||
length += bytes.length;
|
||||
if (length > maxInputBytes) {
|
||||
stream.destroy();
|
||||
|
||||
Reference in New Issue
Block a user