# Corresponding source and local replacement

This archive contains the exact source tarballs for libheif 1.23.7 and libde265
1.1.3, original notices, the applied typed security shim, deterministic build
scripts, and the application-side worker, decoder bridge, policy and loader.
It contains no private application/server source or operational data.

Verify `SHA256SUMS` in the extracted archive, then verify each original tarball
against `build/manifest.json`. The original release archives have no detached
signature supplied here. Their tag commits are recorded for provenance; they
are not a claim of byte equivalence between a Git checkout and release archive.

## Rebuild the library

Use Linux/amd64 and the Emscripten SDK container pinned in `build/manifest.json`:
`emscripten/emsdk@sha256:30aa9fed39cc7810cc4338c77828bd513a6ee6b60c6b141bc6d9760aea5791e3`.
It supplies Emscripten 3.1.61, CMake 3.22.1 and compiler-driver Node 18.20.3.
The SDK is obtained from the official emscripten/emsdk distribution; no SDK
binaries are embedded in this source archive. Python 3 is used for preparation.

1. Copy `build/` to a fresh directory. Run `python3 prepare.py` there to verify
   source hashes, extract tarballs and apply the exact security shim. Adjust
   the asserted patch/manifest deliberately if making a modified version.
2. Bind only that directory at `/evidence` in the pinned SDK container.
   Run `bash /evidence/build.sh 1` in a fresh container, then
   `bash /evidence/build.sh 2` in another fresh container. Recommended bounds:
   `--rm --network=none --cpus=2 --memory=3g --memory-swap=3g --pids-limit=256
   --cap-drop=ALL --security-opt=no-new-privileges --user 1000:1000`.
3. Run `bash /evidence/link-browser.sh` with the same container restrictions.
   The script links both static-library pairs with `ENVIRONMENT=worker`.
   Use `run1/libheif.browser.mjs`, never the Node/worker `libheif.mjs` variant.
   The Node variant has Node builtin imports and is not suitable for a browser.
4. Compare the two browser outputs. `SOURCE_DATE_EPOCH=1789382400`, paths,
   compiler and exact options are fixed in the supplied scripts. Modified
   sources naturally produce new hashes; identify your replacement version.

The shim applies finite limits before parsing, including 25,000,000 pixels,
256 items/tiles, 256 MiB context memory and a 512 MiB maximum WASM heap.
The application bridge additionally checks 8192 pixels per side before RGBA.
These limits do not promise a maximum for total browser/native memory.

## Recombine with the application-side module

`bridge/packages/ui/src/lib/` preserves original module-relative paths. Replace
`heic/vendor/libheif.browser.mjs` with a compatible worker-only ESM factory.
Keep the default factory export and typed API in `libheif.browser.d.mts`, or
adapt `heic/decode.ts` and the declaration together. The narrow boundary is:

- input: `{ file: Blob }` to `heic/heic.worker.ts`;
- output: `{ blob: Blob }` containing a nonempty WebP at most 10 MiB, or
  `{ error: PhotoErrorCode }`;
- native preparation and the worker loader are in `photo-preparation.ts` and
  `heic/worker-client.ts`; the module worker is created through
  `new Worker(new URL('./heic.worker.ts', import.meta.url), { type: 'module' })`.

The bridge can be bundled independently with a module-worker-capable
TypeScript bundler. In a local copy of this application, put these files at
their listed paths, use its locked pnpm dependencies, then rebuild the Main,
DE and EN apps. The consumer uses Next.js 16.2.11, TypeScript 5.9.3 and React
19.2.4; these bridge modules themselves use Web APIs and have no runtime npm
dependency. Serve the resulting worker and its chunks from the same origin.
No runtime integrity gate, signed module requirement, secret or production
account is needed to replace the library in a local rebuilt copy.

Keep WebAssembly compilation permitted by the applicable local CSP and keep
worker execution same-origin. Do not enable eval, blob workers or remote code
to make replacement work. The narrow worker boundary remains the replacement
contract; application/server source unrelated to that boundary is not supplied.

Check the modified result with an owned HEVC fixture, primary selection,
preparse limits, cleanup, dimension/output caps, cancellation and a built
browser/CSP test. Physical iOS and independent license/security review are
separate release checks. No permission to deploy a modified production service
is granted by these replacement instructions.
