fix(browser): compare PNG IHDR bytes without ASCII folding (#2099)
* fix(browser): compare PNG IHDR bytes without ASCII folding Screenshot checks already compare the PNG signature as raw bytes, then decoded the chunk type with an encoding that maps high-bit bytes onto IHDR. Co-authored-by: Cursor <cursoragent@cursor.com> * fix(browser): satisfy the strict index check in the IHDR test Co-authored-by: Cursor <cursoragent@cursor.com> * refactor(browser): share byte-faithful PNG header facts --------- Co-authored-by: Cursor <cursoragent@cursor.com> Co-authored-by: REA preparation lane <rea-preparation@localhost>
This commit is contained in:
co-authored by
Cursor
REA preparation lane
parent
c59fbf5e9c
commit
fdd8f82602
@@ -3,6 +3,7 @@ import { createHash } from "node:crypto";
|
||||
import { z } from "zod";
|
||||
|
||||
import { decodeCanonicalBase64 } from "../webScreenshot.js";
|
||||
import { readPngHeaderDimensions } from "../pngHeader.js";
|
||||
|
||||
const scope = {
|
||||
pid: z.number().int().positive(),
|
||||
@@ -95,11 +96,8 @@ const nativeUiScreenshotSchema = z
|
||||
code: "custom",
|
||||
message: "PNG screenshot digest mismatch",
|
||||
});
|
||||
if (
|
||||
bytes.byteLength < 24 ||
|
||||
!bytes.subarray(0, 8).equals(PNG_SIGNATURE) ||
|
||||
bytes.subarray(12, 16).toString("ascii") !== "IHDR"
|
||||
) {
|
||||
const dimensions = readPngHeaderDimensions(bytes);
|
||||
if (dimensions === undefined) {
|
||||
context.addIssue({
|
||||
code: "custom",
|
||||
message: "Screenshot bytes are not a PNG image",
|
||||
@@ -107,8 +105,8 @@ const nativeUiScreenshotSchema = z
|
||||
return;
|
||||
}
|
||||
if (
|
||||
bytes.readUInt32BE(16) !== screenshot.width ||
|
||||
bytes.readUInt32BE(20) !== screenshot.height
|
||||
dimensions.width !== screenshot.width ||
|
||||
dimensions.height !== screenshot.height
|
||||
)
|
||||
context.addIssue({
|
||||
code: "custom",
|
||||
@@ -116,8 +114,6 @@ const nativeUiScreenshotSchema = z
|
||||
});
|
||||
});
|
||||
|
||||
const PNG_SIGNATURE = Buffer.from([137, 80, 78, 71, 13, 10, 26, 10]);
|
||||
|
||||
export const nativeUiSnapshotSchema = z.strictObject({
|
||||
window: z.strictObject({
|
||||
pid: z.number().int().positive(),
|
||||
|
||||
Reference in New Issue
Block a user