mirror of
https://github.com/morluto/rea
synced 2026-10-28 15:07:26 -04:00
fix(workers): reject malformed UTF-8 in JSON result files
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
import { safeParseUtf8Json } from "../../domain/safeJson.js";
|
||||
import { analysisSettingLimit } from "../../domain/analysisSettingDefinitions.js";
|
||||
import { WorkerFrameSignal } from "../../process/WorkerFrameSignal.js";
|
||||
import type {
|
||||
@@ -719,17 +720,18 @@ export class JavaScriptAnalysisWorker {
|
||||
remediationAction: JAVASCRIPT_PARENT_CHECKPOINT_HEAP_REMEDIATION,
|
||||
},
|
||||
);
|
||||
const text = await readFile(path, "utf8");
|
||||
const checkpoint = await readFile(path);
|
||||
if (
|
||||
expected !== undefined &&
|
||||
createHash("sha256").update(text).digest("hex") !== expected.sha256
|
||||
createHash("sha256").update(checkpoint).digest("hex") !== expected.sha256
|
||||
)
|
||||
throw new AnalysisOutputError(
|
||||
OPERATION,
|
||||
"JavaScript static checkpoint digest does not match",
|
||||
);
|
||||
const value: unknown = JSON.parse(text);
|
||||
const facts = javaScriptWorkerStaticAnalysisSchema.parse(value);
|
||||
const decoded = safeParseUtf8Json(checkpoint);
|
||||
if (!decoded.ok) throw decoded.cause;
|
||||
const facts = javaScriptWorkerStaticAnalysisSchema.parse(decoded.value);
|
||||
const remaining = this.#remainingTotalResultBudget();
|
||||
const retainedBytes = bytes * STATIC_CHECKPOINT_RETENTION_EXPANSION;
|
||||
this.#parentCapacityExhausted = retainedBytes > remaining;
|
||||
|
||||
Reference in New Issue
Block a user