Accept documented Buffer inputs for PNG images

perfloop-oss/satori · Value Kind Confusion

https://perfloop.ai/t/oss/case_fqf359xh1f

Verdict

VERIFIED · settled 2026-11-08 · pull request opened as vercel/satori#965

What happened: The check fails before this change and passes with it.

Hypothesis

The documented Node Buffer image input fails for a valid one-pixel PNG. Image preprocessing rejects the render before layout, although an ArrayBuffer containing the same bytes works. The affected input is a normal supported source representation; its use in production is unknown.

README.md's Images section explicitly lists both src={arrayBuffer} and src={buffer}. resolveImageData classifies every object as an ArrayBuffer and passes the original object to arrayBufferToDataUri. Signature detection constructs a Uint8Array successfully from a Buffer, but parsePNG then constructs a DataView from the original Buffer. A Buffer is a byte view, not an ArrayBuffer, so that constructor throws. This failure does not depend on large dimensions and is independent of the 16-bit dimension loss.

The stored native check on prop_ntr7zpmwsm ran with `pnpm test test/perfloop-png-buffer.test.ts --threads=false`. checkProperty call_QXY4xsKVzK1cfpYNMOEKpe6z exited 1 with both tests failing. Its finite-domain comparison stopped at the smallest case, a complete 1×1 PNG in a Buffer with zero requested offset: the ArrayBuffer returned dimensions [1,1], while the Buffer threw `TypeError: First argument to DataView constructor must be an ArrayBuffer`. A second test confirmed rejection through the public satori operation for a sliced Buffer at offset 7, after the equivalent ArrayBuffer render succeeded. The run returned the one-pixel replay bytes. It did not complete the planned 64-case enumeration.

The Case should restore the documented Buffer behavior while preserving exactly the supplied view's bytes, rather than accidentally including bytes before or after a slice. Replay the one-pixel source, then check ordinary and sliced Buffers against their exact-byte ArrayBuffer equivalents. Other formats' behavior and the most economical shared normalization point remain investigation questions. The stored Vitest file and finite test layout are provisional, not an additional fixed interface requirement.

The actual patches in https://github.com/vercel/satori/pull/953, https://github.com/vercel/satori/pull/810 and https://github.com/vercel/satori/pull/812 do not normalize binary Buffer inputs: they concern deferred HTTP loading, SVG attributes and SVG UTF-8 encoding respectively. Those overlapping files therefore do not cover this repair. The shallow checkout and refused recent-history and Discussions reads remain named upstream evidence gaps.

Change to test: Distinguish ArrayBuffers from supported binary views and normalize Buffer inputs to exactly their byte offset and length before image parsing and inlining. Preserve ArrayBuffer behavior and verify that ordinary and sliced PNG Buffers resolve and render equivalently.

Where it lives

perfloop-oss/satori · src/satori.ts

Evidence

The check fails before this change and passes with it: `For the complete one-pixel PNG fixture, ordinary Node Buffers and slices at offsets 0, 1, 7 and 31 with 0, 1 or 11 trailing backing bytes resolve to the same exact data URI and dimensions and render the same SVG as their exact-byte ArrayBuffers.`

Checks: 1 of 1 passed. Verification: no defect found.

Timeline