mirror of
https://github.com/morluto/rea.git
synced 2026-12-02 19:57:58 +00:00
refactor(elf): share note reader limit error projection (#14644)
This commit is contained in:
1 parent
0e7db4c052
commit
9edc95c512
4 files changed
+67
-92
No files matched your search
@@ -267,11 +267,6 @@
|
||||
"class": "pending",
|
||||
"issue": 14235,
|
||||
"reason": "The streamed candidate is hashed in bounded chunks; its 0xffffffff-byte whole-file ceiling states no format reason, so it is a policy awaiting a control or a stated reason."
|
||||
},
|
||||
"ELF_NOTE_TEXT_ALLOWANCE": {
|
||||
"class": "pending",
|
||||
"issue": 14235,
|
||||
"reason": "Native reader structural, text and inventory allowances are resource policies without a per-call control."
|
||||
}
|
||||
},
|
||||
"src/native/elf/ElfDependenciesProvider.ts": {
|
||||
@@ -281,7 +276,7 @@
|
||||
"reason": "ELF dependency entry allowances are resource policies; the text budget is derived from the admitted image length."
|
||||
}
|
||||
},
|
||||
"src/native/elf/ElfNotesProvider.ts": {
|
||||
"src/native/elf/elfNoteLimitConstraint.ts": {
|
||||
"ELF_NOTE_TEXT_ALLOWANCE": {
|
||||
"class": "pending",
|
||||
"issue": 14235,
|
||||
|
||||
@@ -1,7 +1,4 @@
|
||||
import {
|
||||
isParseLimit,
|
||||
parseLimitConstraint,
|
||||
} from "../../domain/parseFailureAnalysisError.js";
|
||||
import { parseLimitConstraint } from "../../domain/parseFailureAnalysisError.js";
|
||||
import { decodeLimit } from "../../domain/parseFailure.js";
|
||||
import {
|
||||
closeArtifactResources,
|
||||
@@ -41,8 +38,7 @@ import {
|
||||
verifyElfDebugCandidateCooperative,
|
||||
type ElfDebugCandidateFile,
|
||||
} from "./ElfDebugLink.js";
|
||||
import { ELF_NOTE_TEXT_ALLOWANCE } from "./ElfNoteParser.js";
|
||||
import { elfSectionNameBudget } from "../../domain/native/elfSectionNameTable.js";
|
||||
import { elfNoteLimitConstraint } from "./elfNoteLimitConstraint.js";
|
||||
import { elfReadBudgetLimit } from "../../domain/native/elfReadBudgets.js";
|
||||
|
||||
const OPERATION = "inspect_elf_debug_link";
|
||||
@@ -315,43 +311,15 @@ const elfDebugLinkFailure = (
|
||||
field === "candidate_path" ? "debug file candidate" : "ELF image",
|
||||
field,
|
||||
fallbackMessage: "ELF debug-link inspection failed.",
|
||||
recognise: (failure) => {
|
||||
const sectionNameBudget = elfSectionNameBudget(failure);
|
||||
if (isParseLimit(failure, "elf") && sectionNameBudget !== undefined)
|
||||
return parseLimitConstraint(OPERATION, "memory", failure, {
|
||||
retryable: false,
|
||||
limit: elfReadBudgetLimit(
|
||||
recognise: (failure) =>
|
||||
isNativeStructureFailure(failure)
|
||||
? nativeStructureConstraint(OPERATION, failure)
|
||||
: elfNoteLimitConstraint(
|
||||
OPERATION,
|
||||
failure,
|
||||
input,
|
||||
ELF_DEBUG_LINK_READ_BUDGETS,
|
||||
"max_file_bytes",
|
||||
input.max_file_bytes,
|
||||
sectionNameBudget.required,
|
||||
),
|
||||
});
|
||||
if (isNativeStructureFailure(failure))
|
||||
return nativeStructureConstraint(OPERATION, failure);
|
||||
if (isParseLimit(failure, "elf-notes")) {
|
||||
const entryBudget = failure.failure.limit.name === "max_entries";
|
||||
return parseLimitConstraint(
|
||||
OPERATION,
|
||||
entryBudget ? "capacity" : "memory",
|
||||
failure,
|
||||
entryBudget
|
||||
? {
|
||||
retryable: false,
|
||||
limit: elfReadBudgetLimit(
|
||||
ELF_DEBUG_LINK_READ_BUDGETS,
|
||||
"max_entries",
|
||||
input.max_entries,
|
||||
),
|
||||
}
|
||||
: fixedAllowanceOptions(ELF_NOTE_TEXT_ALLOWANCE, "parser", {
|
||||
limit: failure.failure.limit.maximum,
|
||||
unit: "bytes",
|
||||
}),
|
||||
);
|
||||
}
|
||||
return undefined;
|
||||
},
|
||||
fileSize: (failure) => {
|
||||
const candidate = field === "candidate_path";
|
||||
return parseLimitConstraint(
|
||||
|
||||
@@ -1,7 +1,4 @@
|
||||
import {
|
||||
isParseLimit,
|
||||
parseLimitConstraint,
|
||||
} from "../../domain/parseFailureAnalysisError.js";
|
||||
import { parseLimitConstraint } from "../../domain/parseFailureAnalysisError.js";
|
||||
import {
|
||||
projectStableArtifactFailure,
|
||||
closeArtifactResources,
|
||||
@@ -19,7 +16,6 @@ import {
|
||||
projectZstandardFrameAllowance,
|
||||
ZstandardFrameAllowanceError,
|
||||
} from "../../domain/compression/zstandardFrameAllowance.js";
|
||||
import { fixedAllowanceOptions } from "../../domain/fixedAllowanceRemediation.js";
|
||||
import {
|
||||
ELF_NOTES_READ_BUDGETS,
|
||||
type ElfNotes,
|
||||
@@ -28,11 +24,8 @@ import {
|
||||
import { elfReadBudgetLimit } from "../../domain/native/elfReadBudgets.js";
|
||||
import { err, ok } from "../../domain/result.js";
|
||||
import { ELF_NOTES_PROVIDER } from "../../domain/investigationProviders.js";
|
||||
import { elfSectionNameBudget } from "../../domain/native/elfSectionNameTable.js";
|
||||
import {
|
||||
ELF_NOTE_TEXT_ALLOWANCE,
|
||||
parseElfNotesFromHandle,
|
||||
} from "./ElfNoteParser.js";
|
||||
import { elfNoteLimitConstraint } from "./elfNoteLimitConstraint.js";
|
||||
import { parseElfNotesFromHandle } from "./ElfNoteParser.js";
|
||||
|
||||
const OPERATION = "inspect_elf_notes";
|
||||
const HEADER_PREFIX_BYTES = 4096;
|
||||
@@ -106,43 +99,15 @@ const elfNotesFailure = (
|
||||
path: input.path,
|
||||
description: "ELF image",
|
||||
fallbackMessage: "ELF note inspection failed.",
|
||||
recognise: (failure) => {
|
||||
if (failure instanceof ZstandardFrameAllowanceError)
|
||||
return projectZstandardFrameAllowance(OPERATION, failure);
|
||||
const sectionNameBudget = elfSectionNameBudget(failure);
|
||||
if (isParseLimit(failure, "elf") && sectionNameBudget !== undefined)
|
||||
return parseLimitConstraint(OPERATION, "memory", failure, {
|
||||
retryable: false,
|
||||
limit: elfReadBudgetLimit(
|
||||
recognise: (failure) =>
|
||||
failure instanceof ZstandardFrameAllowanceError
|
||||
? projectZstandardFrameAllowance(OPERATION, failure)
|
||||
: elfNoteLimitConstraint(
|
||||
OPERATION,
|
||||
failure,
|
||||
input,
|
||||
ELF_NOTES_READ_BUDGETS,
|
||||
"max_file_bytes",
|
||||
input.max_file_bytes,
|
||||
sectionNameBudget.required,
|
||||
),
|
||||
});
|
||||
if (isParseLimit(failure, "elf-notes")) {
|
||||
const entryBudget = failure.failure.limit.name === "max_entries";
|
||||
return parseLimitConstraint(
|
||||
OPERATION,
|
||||
entryBudget ? "capacity" : "memory",
|
||||
failure,
|
||||
entryBudget
|
||||
? {
|
||||
retryable: false,
|
||||
limit: elfReadBudgetLimit(
|
||||
ELF_NOTES_READ_BUDGETS,
|
||||
"max_entries",
|
||||
input.max_entries,
|
||||
),
|
||||
}
|
||||
: fixedAllowanceOptions(ELF_NOTE_TEXT_ALLOWANCE, "parser", {
|
||||
limit: failure.failure.limit.maximum,
|
||||
unit: "bytes",
|
||||
}),
|
||||
);
|
||||
}
|
||||
return undefined;
|
||||
},
|
||||
fileSize: (failure) =>
|
||||
parseLimitConstraint(
|
||||
OPERATION,
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
import { fixedAllowanceOptions } from "../../domain/fixedAllowanceRemediation.js";
|
||||
import {
|
||||
elfReadBudgetLimit,
|
||||
type ElfReadBudgets,
|
||||
} from "../../domain/native/elfReadBudgets.js";
|
||||
import { elfSectionNameBudget } from "../../domain/native/elfSectionNameTable.js";
|
||||
import {
|
||||
isParseLimit,
|
||||
parseLimitConstraint,
|
||||
} from "../../domain/parseFailureAnalysisError.js";
|
||||
import { ELF_NOTE_TEXT_ALLOWANCE } from "./ElfNoteParser.js";
|
||||
|
||||
/** Project a shared note-reader limit using the calling operation's bounds. */
|
||||
export const elfNoteLimitConstraint = (
|
||||
operation: string,
|
||||
failure: unknown,
|
||||
input: Readonly<Record<keyof ElfReadBudgets, number>>,
|
||||
budgets: ElfReadBudgets,
|
||||
) => {
|
||||
const sectionNameBudget = elfSectionNameBudget(failure);
|
||||
if (isParseLimit(failure, "elf") && sectionNameBudget !== undefined)
|
||||
return parseLimitConstraint(operation, "memory", failure, {
|
||||
retryable: false,
|
||||
limit: elfReadBudgetLimit(
|
||||
budgets,
|
||||
"max_file_bytes",
|
||||
input.max_file_bytes,
|
||||
sectionNameBudget.required,
|
||||
),
|
||||
});
|
||||
if (!isParseLimit(failure, "elf-notes")) return undefined;
|
||||
const entryBudget = failure.failure.limit.name === "max_entries";
|
||||
return parseLimitConstraint(
|
||||
operation,
|
||||
entryBudget ? "capacity" : "memory",
|
||||
failure,
|
||||
entryBudget
|
||||
? {
|
||||
retryable: false,
|
||||
limit: elfReadBudgetLimit(budgets, "max_entries", input.max_entries),
|
||||
}
|
||||
: fixedAllowanceOptions(ELF_NOTE_TEXT_ALLOWANCE, "parser", {
|
||||
limit: failure.failure.limit.maximum,
|
||||
unit: "bytes",
|
||||
}),
|
||||
);
|
||||
};
|
||||
Reference in new issue
Block a user