mirror of
https://github.com/morluto/rea.git
synced 2026-11-21 06:04:03 +00:00
fix(desktop): validate Debian package control output as UTF-8 (#12355)
This commit is contained in:
1 parent
14aca264ea
commit
1cf9bc86c8
4 files changed
+46
-10
No files matched your search
@@ -25,8 +25,9 @@ capture nor the bundle holds the package.
|
||||
entries of each relationship field as the file declares them. Otherwise
|
||||
`package_file_reason` says why: dpkg reports no installed version of the
|
||||
application, the path is not a regular file, `dpkg-deb` is missing or cannot
|
||||
read it, it lacks one of the three fields, it holds another package, version
|
||||
or architecture, or it could not be read. A descriptor whose close fails
|
||||
read it, the reported fields contain invalid UTF-8 or lack one of the three
|
||||
identity fields, it holds another package, version or architecture, or it
|
||||
could not be read. A descriptor whose close fails
|
||||
fails the capture with its owner. The file is never copied into the capture
|
||||
folder.
|
||||
- Library packages are walked as for a vendor repository's package also for a
|
||||
|
||||
@@ -34,9 +34,11 @@ const inspect = async (
|
||||
const facts = await inspectPackageFile(
|
||||
path,
|
||||
installed,
|
||||
async (command, argv) => {
|
||||
async (command, argv, _signal, options) => {
|
||||
calls.push([command, ...argv]);
|
||||
return reply;
|
||||
return typeof reply === "object" && !options?.preserveStdoutBytes
|
||||
? { stdout: reply.stdout, exitCode: reply.exitCode }
|
||||
: reply;
|
||||
},
|
||||
undefined,
|
||||
);
|
||||
@@ -76,6 +78,32 @@ describe("inspectPackageFile", () => {
|
||||
});
|
||||
});
|
||||
|
||||
it("withholds package-file evidence for undecodable control fields", async () => {
|
||||
const stdoutBuffer = Buffer.concat([
|
||||
Buffer.from(DPKG_DEB_OUTPUT.trimEnd()),
|
||||
Buffer.from([0xff, 0x0a]),
|
||||
]);
|
||||
const invalid = await inspect({
|
||||
stdout: stdoutBuffer.toString("utf8"),
|
||||
stdoutBuffer,
|
||||
exitCode: 0,
|
||||
});
|
||||
expect(invalid.facts).toEqual({
|
||||
package_file_reason: `dpkg-deb returned invalid UTF-8 in the control fields of ${invalid.path}`,
|
||||
});
|
||||
|
||||
const valid = await inspect({
|
||||
stdout: "",
|
||||
stdoutBuffer: Buffer.from(DPKG_DEB_OUTPUT),
|
||||
exitCode: 0,
|
||||
});
|
||||
expect(valid.facts.package_file).toMatchObject({
|
||||
package: INSTALLED.name,
|
||||
version: INSTALLED.version,
|
||||
architecture: INSTALLED.architecture,
|
||||
});
|
||||
});
|
||||
|
||||
it("records why instead when the file holds another version", async () => {
|
||||
const { path, facts } = await inspect(
|
||||
{ stdout: DPKG_DEB_OUTPUT, exitCode: 0 },
|
||||
|
||||
@@ -26,7 +26,7 @@ import {
|
||||
hostFileKind,
|
||||
isRefusedRead,
|
||||
} from "./HostFileRead.js";
|
||||
import type { QueryRunner } from "./HostQuery.js";
|
||||
import { queryUtf8Text, type QueryRunner } from "./HostQuery.js";
|
||||
import { errorMessage } from "../kernel/errorMessage.js";
|
||||
|
||||
type PackageFileFacts = Pick<
|
||||
@@ -103,18 +103,23 @@ export const inspectPackageFile = async (
|
||||
// dpkg-deb and the hash read the file apart; its identity must hold across both.
|
||||
const before = await stat(path).catch(() => undefined);
|
||||
if (before === undefined) return refused(`${path} could not be read`);
|
||||
const outcome = await runQuery(
|
||||
const outcome = await queryUtf8Text(
|
||||
runQuery,
|
||||
"dpkg-deb",
|
||||
["--field", path, ...PACKAGE_FILE_FIELDS],
|
||||
signal,
|
||||
);
|
||||
if (outcome === "missing")
|
||||
if (outcome.kind === "missing")
|
||||
return refused(
|
||||
`dpkg-deb is not installed, so the control fields of ${path} were not read`,
|
||||
);
|
||||
if (outcome === "failed" || outcome.exitCode !== 0)
|
||||
if (outcome.kind === "undecodable")
|
||||
return refused(
|
||||
`dpkg-deb returned invalid UTF-8 in the control fields of ${path}`,
|
||||
);
|
||||
if (outcome.kind !== "read")
|
||||
return refused(`dpkg-deb could not read ${path} as a Debian package`);
|
||||
const fields = parseDpkgDebFields(outcome.stdout);
|
||||
const fields = parseDpkgDebFields(outcome.text);
|
||||
if (fields === undefined)
|
||||
return refused(
|
||||
`dpkg-deb did not report the Package, Version and Architecture of ${path}`,
|
||||
|
||||
@@ -76,11 +76,13 @@ export const queryUtf8Text = async (
|
||||
args: readonly string[],
|
||||
signal: AbortSignal | undefined,
|
||||
): Promise<
|
||||
{ kind: "read"; text: string } | { kind: "undecodable" | "unavailable" }
|
||||
| { kind: "read"; text: string }
|
||||
| { kind: "missing" | "undecodable" | "unavailable" }
|
||||
> => {
|
||||
const outcome = await runQuery(command, args, signal, {
|
||||
preserveStdoutBytes: true,
|
||||
});
|
||||
if (outcome === "missing") return { kind: "missing" };
|
||||
if (typeof outcome !== "object" || outcome.exitCode !== 0)
|
||||
return { kind: "unavailable" };
|
||||
if (outcome.stdoutBuffer !== undefined && !isStrictUtf8(outcome.stdoutBuffer))
|
||||
|
||||
Reference in new issue
Block a user