mirror of
https://github.com/boykopovar/AnyPS5.git
synced 2026-11-05 13:20:11 +00:00
Merge pull request #11807 from StoneDC/fix/web-memory-estimate-inputs
fix(web): validate every memory estimate input
This commit is contained in:
2 files changed
+15
No files matched your search
@@ -6,6 +6,7 @@ function safeSize(value) {
|
||||
}
|
||||
|
||||
export function memoryEstimate(archiveBytes, selectedBytes, libraryBytes, entries) {
|
||||
for (const value of [archiveBytes, selectedBytes, libraryBytes, entries]) safeSize(value);
|
||||
return safeSize(Math.ceil(archiveBytes * 1.02) + selectedBytes * 4 + libraryBytes + entries * 1024 + 8 * 1024 * 1024);
|
||||
}
|
||||
|
||||
|
||||
@@ -2,6 +2,20 @@ import assert from "node:assert/strict";
|
||||
import { test } from "node:test";
|
||||
import { batchMemoryEstimate, batchOutputDirectory, memoryEstimate, MEMORY_LIMIT } from "../batch.mjs";
|
||||
|
||||
test("rejects each invalid memory operand before arithmetic can coerce or cancel it", () => {
|
||||
for (let index = 0; index < 4; index++) {
|
||||
for (const value of [-1, -100000000, "1024", null, true, NaN, Infinity, 1.5, Number.MAX_SAFE_INTEGER + 1]) {
|
||||
const operands = [1024, 70 * 1024 * 1024, 0, 2];
|
||||
operands[index] = value;
|
||||
assert.throws(() => memoryEstimate(...operands), /unsupported file size/u);
|
||||
}
|
||||
}
|
||||
const summaries = [{totalBytes: 1024, selectedBytes: 70 * 1024 * 1024, windowsSelectedBytes: 70 * 1024 * 1024, files: 2}];
|
||||
assert.ok(batchMemoryEstimate(summaries, "linux", 0) > MEMORY_LIMIT);
|
||||
assert.throws(() => batchMemoryEstimate(summaries, "linux", -100000000), /unsupported file size/u);
|
||||
assert.equal(memoryEstimate(0, 0, 0, 0), 8 * 1024 * 1024);
|
||||
});
|
||||
|
||||
test("estimates all ZIP outputs against one shared memory limit", () => {
|
||||
const summaries = [
|
||||
{ totalBytes: 1024, selectedBytes: 128, windowsSelectedBytes: 256, files: 2 },
|
||||
|
||||
Reference in new issue
Block a user