























@@ -1740,7 +1740,7 @@ function parsePosixProcessRows(stdout) {
17401740const processId = Number.parseInt(pidRaw, 10);
17411741const parentProcessId = Number.parseInt(ppidRaw, 10);
17421742const rssKb = Number.parseInt(rssKbRaw, 10);
1743-const cpuPercent = parsePosixCpuPercent(cpuRaw);
1743+const cpuPercent = parseStrictNonNegativeDecimal(cpuRaw);
17441744if (
17451745!Number.isInteger(processId) ||
17461746!Number.isInteger(parentProcessId) ||
@@ -1759,7 +1759,7 @@ function parsePosixProcessRows(stdout) {
17591759.filter(Boolean);
17601760}
176117611762-function parsePosixCpuPercent(raw) {
1762+function parseStrictNonNegativeDecimal(raw) {
17631763const text = String(raw ?? "").trim();
17641764if (!/^(?:0|[1-9]\d*)(?:\.\d+)?$/u.test(text)) {
17651765return null;
@@ -1768,6 +1768,15 @@ function parsePosixCpuPercent(raw) {
17681768return Number.isFinite(parsed) ? parsed : null;
17691769}
177017701771+function parseStrictUnsignedInteger(raw) {
1772+const text = String(raw ?? "").trim();
1773+if (!/^(?:0|[1-9]\d*)$/u.test(text)) {
1774+return null;
1775+}
1776+const parsed = Number(text);
1777+return Number.isSafeInteger(parsed) ? parsed : null;
1778+}
1779+17711780function collectPosixProcessTree(rows, rootPid) {
17721781const byParent = new Map();
17731782for (const row of rows) {
@@ -1949,24 +1958,24 @@ async function sampleWindowsProcess(pid, run, commandLineNeedles = []) {
19491958const [workingSetBytesRaw, cpuSecondsRaw, processIdRaw, aggregateWorkingSetBytesRaw] = stdout
19501959.trim()
19511960.split(/\s+/u);
1952-const workingSetBytes = Number.parseInt(workingSetBytesRaw ?? "", 10);
1953-const aggregateWorkingSetBytes = Number.parseInt(
1961+const workingSetBytes = parseStrictUnsignedInteger(workingSetBytesRaw);
1962+const aggregateWorkingSetBytes = parseStrictUnsignedInteger(
19541963aggregateWorkingSetBytesRaw ?? workingSetBytesRaw ?? "",
1955-10,
19561964);
1957-const cpuSeconds = Number.parseFloat(cpuSecondsRaw ?? "");
1958-const processId = Number.parseInt(processIdRaw ?? "", 10);
1959-if (!Number.isFinite(workingSetBytes)) {
1965+const cpuSeconds = parseStrictNonNegativeDecimal(cpuSecondsRaw);
1966+const processId = parseStrictUnsignedInteger(processIdRaw);
1967+if (workingSetBytes === null) {
19601968return null;
19611969}
19621970return {
19631971rssMiB: Math.round((workingSetBytes / 1024 / 1024) * 10) / 10,
1964-aggregateRssMiB: Number.isFinite(aggregateWorkingSetBytes)
1965- ? Math.round((aggregateWorkingSetBytes / 1024 / 1024) * 10) / 10
1966- : Math.round((workingSetBytes / 1024 / 1024) * 10) / 10,
1972+aggregateRssMiB:
1973+aggregateWorkingSetBytes !== null
1974+ ? Math.round((aggregateWorkingSetBytes / 1024 / 1024) * 10) / 10
1975+ : Math.round((workingSetBytes / 1024 / 1024) * 10) / 10,
19671976cpuPercent: null,
1968-cpuSeconds: Number.isFinite(cpuSeconds) ? cpuSeconds : null,
1969-processId: Number.isFinite(processId) ? processId : safePid,
1977+ cpuSeconds,
1978+processId: processId ?? safePid,
19701979};
19711980} catch {
19721981// Try the next Windows PowerShell command name.
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。