forked from mtusi2026/mtusi2026lab4
lab4: исправления второго ревью (40 Мп в tmpfs, таймауты S3, параллельный complete, auth до Content-Type, лимит на пользователя, бюджет памяти декода)
This commit is contained in:
@@ -8,3 +8,17 @@ export function jpegWithoutScanData(jpeg: Buffer): Buffer {
|
||||
}
|
||||
return Buffer.concat([jpeg.subarray(0, offset), Buffer.from([0xff, 0xd9])]);
|
||||
}
|
||||
|
||||
/** Inserts `count` APP13 segments of ~64 KiB right after SOI (Photoshop-style metadata). */
|
||||
export function jpegWithMetadata(jpeg: Buffer, count: number): Buffer {
|
||||
const payload = Buffer.alloc(65_533, 0x20);
|
||||
const segment = Buffer.concat([
|
||||
Buffer.from([0xff, 0xed, 0xff, 0xff]),
|
||||
payload,
|
||||
]);
|
||||
return Buffer.concat([
|
||||
jpeg.subarray(0, 2),
|
||||
...Array.from({ length: count }, () => segment),
|
||||
jpeg.subarray(2),
|
||||
]);
|
||||
}
|
||||
|
||||
+35
-1
@@ -1,5 +1,6 @@
|
||||
import { randomBytes } from 'node:crypto';
|
||||
import { crc32, deflateSync } from 'node:zlib';
|
||||
import { once } from 'node:events';
|
||||
import { crc32, createDeflate, deflateSync } from 'node:zlib';
|
||||
|
||||
const SIGNATURE = Buffer.from([0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a]);
|
||||
|
||||
@@ -104,3 +105,36 @@ export function pngWithGarbageIdat(): Buffer {
|
||||
idat: randomBytes(5000),
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 8000x5000 RGBA 16-bit (8 bytes/pixel, 40 000 000 px — the pixel limit):
|
||||
* the heaviest decode a valid upload can ask for. Rows are streamed into the
|
||||
* compressor, so the 320 MB raw image is never allocated here.
|
||||
*/
|
||||
export async function maxPixelsRgba16Png(): Promise<Buffer> {
|
||||
const width = 8000;
|
||||
const height = 5000;
|
||||
// First row: a gradient; every next row uses filter "Up" with zero
|
||||
// deltas, i.e. repeats it — a valid image that compresses well.
|
||||
const first = Buffer.alloc(1 + width * 8);
|
||||
for (let x = 0; x < width; x += 1)
|
||||
first.writeUInt16BE((x * 8) & 0xffff, 1 + x * 8);
|
||||
const repeat = Buffer.alloc(1 + width * 8);
|
||||
repeat[0] = 2;
|
||||
const deflate = createDeflate({ level: 1 });
|
||||
const chunks: Buffer[] = [];
|
||||
deflate.on('data', (chunk: Buffer) => chunks.push(chunk));
|
||||
const ended = once(deflate, 'end');
|
||||
for (let y = 0; y < height; y += 1)
|
||||
if (!deflate.write(y === 0 ? first : repeat))
|
||||
await once(deflate, 'drain');
|
||||
deflate.end();
|
||||
await ended;
|
||||
return buildPng({
|
||||
width,
|
||||
height,
|
||||
colorType: 6,
|
||||
bitDepth: 16,
|
||||
idat: Buffer.concat(chunks),
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user