Skip to content

Commit b6925c8

Browse files
committed
fix(server): copy extracted .icns PNG out of file buffer
The subarray view kept the whole .icns buffer alive while the asset response was sent.
1 parent b013db1 commit b6925c8

1 file changed

Lines changed: 5 additions & 2 deletions

File tree

‎apps/server/src/assets/icns.ts‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@ const ICNS_HEADER_BYTES = 8;
44
const ICNS_MAGIC = 0x69636e73; // "icns"
55
const PNG_MAGIC = 0x89504e47; // "\x89PNG"
66

7-
/** Picks the smallest PNG at least `minSize` wide, else the largest; null when there is none. */
7+
/**
8+
* Picks the smallest PNG at least `minSize` wide, else the largest; null when there is none.
9+
* Returns a copy so the response does not pin the whole `.icns` buffer.
10+
*/
811
export function extractIcnsPng(bytes: Uint8Array, minSize: number): Uint8Array | null {
912
const data = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
1013
if (bytes.length < ICNS_HEADER_BYTES || data.getUint32(0) !== ICNS_MAGIC) return null;
@@ -23,5 +26,5 @@ export function extractIcnsPng(bytes: Uint8Array, minSize: number): Uint8Array |
2326
(best.width < minSize ? width > best.width : width >= minSize && width < best.width);
2427
if (isBetter) best = { png: entry, width };
2528
}
26-
return best?.png ?? null;
29+
return best?.png.slice() ?? null;
2730
}

0 commit comments

Comments
 (0)