@devries-cameron20 / t3code-1 / commits / 6262c9a2ba
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

fix(screenshots): reject corrupt PNGs during validation (#23161)

Co-authored-by: GPT-6.1 Sol <noreply@openai.com>

Victor Vogel committed Oct 31, 2026 at 21:25 UTC 6262c9a2ba51fec145bf3efd35126ce72739a8be
2 files changed +56
scripts/mobile-showcase.test.ts
+51
@@ -2,11 +2,13 @@
2 import { assert, it } from "@effect/vitest";
3 import { PNG } from "pngjs";
4
5 +import type { ShowcaseStoreAssetSpec } from "./mobile-showcase.config.ts";
6 import {
7 encodeAndroidPairingUrls,
8 normalizeStorePng,
9 parsePairingCredentialOutput,
10 readPngMetadata,
11 + validateStoreAsset,
12 } from "./mobile-showcase.ts";
13
14 function rgbaPng(width: number, height: number): Buffer {
@@ -26,6 +28,55 @@ it("converts simulator RGBA captures to upload-safe 24-bit RGB PNGs", () => {
28 });
29 });
30
31 +const storeSpec: ShowcaseStoreAssetSpec = {
32 + store: "apple",
33 + directory: "fixture",
34 + width: 2,
35 + height: 3,
36 + minimumUploadCount: 1,
37 + maximumUploadCount: 10,
38 +};
39 +
40 +it("validates a complete RGB PNG from an offset byte view", () => {
41 + const bytes = normalizeStorePng(rgbaPng(2, 3));
42 + const padded = Buffer.concat([Buffer.from([0]), bytes, Buffer.from([0])]);
43 + assert.deepStrictEqual(validateStoreAsset(storeSpec, padded.subarray(1, -1)), {
44 + width: 2,
45 + height: 3,
46 + bitDepth: 8,
47 + colorType: 2,
48 + hasAlpha: false,
49 + });
50 +});
51 +
52 +it("rejects PNG metadata without image data during store validation", () => {
53 + const bytes = normalizeStorePng(rgbaPng(2, 3));
54 + assert.throws(
55 + () => validateStoreAsset(storeSpec, bytes.subarray(0, 26), "threads.png"),
56 + /threads\.png is not a valid PNG/,
57 + );
58 + assert.throws(() => validateStoreAsset(storeSpec, bytes.subarray(0, 33)), /is not a valid PNG/);
59 +});
60 +
61 +it("rejects a PNG truncated inside its image data", () => {
62 + const bytes = normalizeStorePng(rgbaPng(2, 3));
63 + const imageData = bytes.indexOf("IDAT");
64 + assert.notEqual(imageData, -1);
65 + assert.throws(
66 + () => validateStoreAsset(storeSpec, bytes.subarray(0, imageData + 5)),
67 + /is not a valid PNG/,
68 + );
69 +});
70 +
71 +it("rejects a PNG with a corrupt image-data checksum", () => {
72 + const bytes = normalizeStorePng(rgbaPng(2, 3));
73 + const imageData = bytes.indexOf("IDAT");
74 + assert.notEqual(imageData, -1);
75 + const checksum = imageData + 4 + bytes.readUInt32BE(imageData - 4);
76 + bytes[checksum] = bytes.readUInt8(checksum) ^ 1;
77 + assert.throws(() => validateStoreAsset(storeSpec, bytes), /is not a valid PNG/);
78 +});
79 +
80 it("reads multiline JSON from the pairing CLI", () => {
81 assert.equal(
82 parsePairingCredentialOutput('server log\n{\n "credential": "PAIR-ME"\n}\n'),
scripts/mobile-showcase.ts
+5
@@ -206,6 +206,11 @@ export function validateStoreAsset(
206 throw new Error(`${label} must use Google Play's recommended portrait 9:16 aspect ratio.`);
207 }
208 }
209 + try {
210 + PNG.sync.read(Buffer.from(bytes));
211 + } catch (cause) {
212 + throw new Error(`${label} is not a valid PNG.`, { cause });
213 + }
214 return metadata;
215 }
216