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
@@ -90,6 +90,33 @@ describe("native UI screenshot validation", () => {
|
||||
},
|
||||
);
|
||||
|
||||
it("rejects a PNG whose IHDR type only matches after ASCII folding", async () => {
|
||||
const bytes = Buffer.from(validPng);
|
||||
const type = bytes.subarray(12, 16);
|
||||
type[0] = (type[0] ?? 0) | 0x80;
|
||||
expect(type.toString("ascii")).toBe("IHDR");
|
||||
const screenshot = {
|
||||
mime_type: "image/png",
|
||||
base64: bytes.toString("base64"),
|
||||
sha256: createHash("sha256").update(bytes).digest("hex"),
|
||||
width: 1,
|
||||
height: 1,
|
||||
};
|
||||
const result = await observeNativeUi(
|
||||
target,
|
||||
"observe_native_ui",
|
||||
{ ...scope, screenshot: true },
|
||||
{
|
||||
environment: {},
|
||||
invoke: async () => ({
|
||||
ok: true,
|
||||
result: { ...snapshot, screenshot },
|
||||
}),
|
||||
},
|
||||
);
|
||||
expect(result.ok).toBe(false);
|
||||
});
|
||||
|
||||
it("accepts a self-consistent PNG screenshot from the helper", async () => {
|
||||
const bytes = validPng;
|
||||
const screenshot = {
|
||||
|
||||
Reference in New Issue
Block a user