fix(adb): reject unsafe host file names when pulling one device file (#1962)
pull_adb_file derived its host file name from the last path segment of a caller-supplied device path and joined it to the output directory without checking that the name is usable on the host. A device path ending in a separator, a dot segment, a control character, a Windows reserved device name, a trailing dot or space, or a ':' alternate-data-stream marker could resolve to an unexpected host path or fail opaquely after the transfer. The single-file path now derives the name with POSIX semantics and refuses any non-portable segment as invalid_request before creating a directory or running adb pull. This matches the package path's pending host-name policy and never renames a device-reported file. Co-authored-by: morluto <76467478+morluto@users.noreply.github.com>
This commit is contained in:
+14
-3
@@ -2,7 +2,7 @@ import { execFile } from "node:child_process";
|
||||
import { createHash } from "node:crypto";
|
||||
import { constants as fsConstants } from "node:fs";
|
||||
import { access, lstat, mkdir, rm, stat, writeFile } from "node:fs/promises";
|
||||
import { basename, join, resolve } from "node:path";
|
||||
import { join, resolve } from "node:path";
|
||||
|
||||
import type {
|
||||
ExecutionOptions,
|
||||
@@ -47,6 +47,7 @@ import {
|
||||
parsePackageListOutput,
|
||||
parsePmPathOutput,
|
||||
} from "./AdbDeviceOutput.js";
|
||||
import { adbHostFileName } from "./AdbHostFileName.js";
|
||||
import {
|
||||
parseAmStartOutput,
|
||||
parseBugreportCopiedPath,
|
||||
@@ -1399,13 +1400,23 @@ export class AdbProvider {
|
||||
},
|
||||
signal: AbortSignal | undefined,
|
||||
): Promise<Result<AnalysisExecution, AnalysisError>> {
|
||||
const derived = adbHostFileName(input.device_path);
|
||||
if (!derived.ok)
|
||||
return err(
|
||||
new AnalysisInputError(operation, undefined, [
|
||||
{
|
||||
path: ["device_path"],
|
||||
reason: "invalid_value",
|
||||
message: `The device path does not name a portable host file (${derived.reason}); REA never renames a device-reported file.`,
|
||||
},
|
||||
]),
|
||||
);
|
||||
const directory = await prepareOutputDirectory(
|
||||
operation,
|
||||
input.output_directory,
|
||||
);
|
||||
if (!directory.ok) return directory;
|
||||
const fileName = basename(input.device_path) || "pulled";
|
||||
const localPath = join(directory.value, fileName);
|
||||
const localPath = join(directory.value, derived.fileName);
|
||||
const existing = await refuseExistingTarget(operation, localPath);
|
||||
if (existing !== undefined) return err(existing);
|
||||
const pulled = await runAdb(
|
||||
|
||||
Reference in New Issue
Block a user