|
5 | 5 | * to the client (sampling, elicitation, roots), the task tools, logging, |
6 | 6 | * subscriptions and gzip each have their own file. |
7 | 7 | */ |
| 8 | +import { crc32 } from "node:zlib"; |
8 | 9 | import { afterEach, beforeEach, describe, expect, it, vi } from "vitest"; |
9 | 10 | import { INCLUDE_SECRETS_VAR, REDACTED } from "../tools/get-env.js"; |
10 | 11 | import { MCP_TINY_IMAGE } from "../tools/get-tiny-image.js"; |
@@ -171,6 +172,34 @@ describe("get-tiny-image", () => { |
171 | 172 | Buffer.from(MCP_TINY_IMAGE, "base64").subarray(1, 4).toString(), |
172 | 173 | ).toBe("PNG"); |
173 | 174 | }); |
| 175 | + |
| 176 | + // #5208: the embedded PNG once carried an iCCP chunk whose CRC did not |
| 177 | + // match, which strict decoders reject. Walk every chunk of the image the |
| 178 | + // client receives and check its stored CRC-32 against its type and data. |
| 179 | + it("returns a PNG whose every chunk has a valid CRC", async () => { |
| 180 | + const result = await call("get-tiny-image"); |
| 181 | + const image = contentOfType(contentOf(result)[1], "image"); |
| 182 | + const png = Buffer.from(image.data, "base64"); |
| 183 | + expect(png.subarray(0, 8)).toEqual( |
| 184 | + Buffer.from([0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a]), |
| 185 | + ); |
| 186 | + const chunks: string[] = []; |
| 187 | + let offset = 8; |
| 188 | + while (offset < png.length) { |
| 189 | + const length = png.readUInt32BE(offset); |
| 190 | + const type = png.subarray(offset + 4, offset + 8).toString("latin1"); |
| 191 | + const stored = png.readUInt32BE(offset + 8 + length); |
| 192 | + expect(crc32(png.subarray(offset + 4, offset + 8 + length)), type).toBe( |
| 193 | + stored, |
| 194 | + ); |
| 195 | + chunks.push(type); |
| 196 | + offset += 12 + length; |
| 197 | + } |
| 198 | + expect(offset).toBe(png.length); |
| 199 | + expect(chunks[0]).toBe("IHDR"); |
| 200 | + expect(chunks.at(-1)).toBe("IEND"); |
| 201 | + expect(chunks).toContain("IDAT"); |
| 202 | + }); |
174 | 203 | }); |
175 | 204 |
|
176 | 205 | describe("get-structured-content", () => { |
|
0 commit comments