mirror of
https://github.com/morluto/rea.git
synced 2026-11-16 11:43:20 +00:00
fix(javascript): reject FIFO recovery inputs without blocking (#3788)
* fix(javascript): reject FIFO recovery inputs without blocking scanRecoveryFile opened the selected path with a blocking O_RDONLY open before checking that it is a regular file. A FIFO with no writer blocks that open in the libuv threadpool, so cancellation and the recovery deadline could not settle the read, and the process could not exit. Admit the input through the shared openRegularFile owner, which opens with O_NONBLOCK and verifies a regular file before any read. A FIFO, directory or socket now fails admission immediately with the existing regular-file error; symlink rejection and cancellation are unchanged. Fixes #3332 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix(javascript): keep a failed admission close owned on cancellation Rethrow RegularFileAdmissionFailure before mapping cancellation, so a descriptor whose close failed stays owned by its error. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
4692bb3330
commit
baad9eebe4
3 files changed
+109
-5
No files matched your search
@@ -1,6 +1,5 @@
|
||||
import { createHash } from "node:crypto";
|
||||
import { constants } from "node:fs";
|
||||
import { lstat, mkdir, open, opendir, writeFile } from "node:fs/promises";
|
||||
import { lstat, mkdir, opendir, writeFile } from "node:fs/promises";
|
||||
import { dirname, isAbsolute, join, relative, resolve, sep } from "node:path";
|
||||
import { TextDecoder } from "node:util";
|
||||
import { normalizeArtifactPath } from "../../artifacts/ArtifactPaths.js";
|
||||
@@ -10,6 +9,11 @@ import {
|
||||
AnalysisOutputError,
|
||||
AnalysisTimeoutError,
|
||||
} from "../../domain/analysisErrorCore.js";
|
||||
import {
|
||||
NonRegularFileReadError,
|
||||
openRegularFile,
|
||||
RegularFileAdmissionFailure,
|
||||
} from "../../filesystem/RegularFile.js";
|
||||
import { RECOVERY_LIMITS } from "./WakaruRelease.js";
|
||||
|
||||
const OPERATION = "recover_javascript_sources";
|
||||
@@ -25,11 +29,26 @@ const scanRecoveryFile = async (
|
||||
consume: (chunk: Buffer) => void,
|
||||
signal?: AbortSignal,
|
||||
) => {
|
||||
const handle = await open(path, constants.O_RDONLY | constants.O_NOFOLLOW);
|
||||
// A FIFO without a writer must be rejected before it can block the open.
|
||||
const handle = await openRegularFile(path, {
|
||||
symlinks: "reject",
|
||||
signal,
|
||||
}).catch((cause: unknown) => {
|
||||
// A descriptor whose close failed stays owned by its error, even when
|
||||
// cancellation was also requested.
|
||||
if (cause instanceof RegularFileAdmissionFailure) throw cause;
|
||||
checkRecoveryCancellation(signal);
|
||||
if (cause instanceof NonRegularFileReadError)
|
||||
throw new AnalysisOutputError(
|
||||
OPERATION,
|
||||
`Expected a regular file no larger than ${String(maximum)} bytes: ${path}`,
|
||||
);
|
||||
throw cause;
|
||||
});
|
||||
const hash = createHash("sha256");
|
||||
try {
|
||||
const before = await handle.stat();
|
||||
if (!before.isFile() || before.size > maximum)
|
||||
if (before.size > maximum)
|
||||
throw new AnalysisOutputError(
|
||||
OPERATION,
|
||||
`Expected a regular file no larger than ${String(maximum)} bytes: ${path}`,
|
||||
|
||||
Reference in new issue
Block a user