taglib-wasm
Version:
TagLib-Wasm is the universal tagging library for TypeScript/JavaScript platforms: Browsers, Node.js, Deno, Bun, Cloudflare Workers, and Electron apps
41 lines • 2.24 kB
TypeScript
/**
* @fileoverview Is a file's metadata provably contained in its first N bytes?
*
* Partial loading (`TagLib.open(path, { partial: true })`) hands TagLib the
* file's first `maxHeaderSize` bytes concatenated with its last `maxFooterSize`
* bytes, discarding the middle. That is only sound when the metadata lives
* entirely inside the header window: otherwise the tag is cut mid-structure and
* unrelated footer bytes are spliced onto the cut, so TagLib parses whatever
* lands there. Measured on a real library, 18 of 40 large MP3s read back
* DIFFERENT metadata that way, and before taglib-f5hp the malformed image also
* tripped a double free that trapped the whole Wasm module (taglib-f5hp).
*
* So the decision is made before splicing, and the rule is deliberately
* asymmetric: return true ONLY when the metadata is provably contained. Anything
* unrecognised, malformed, or unbounded answers false, which costs a full read
* and never costs correctness.
*/
/**
* True only when the metadata of `header` provably ends within `limit` bytes.
*
* `header` is the start of the file and may be shorter than `limit`; anything
* this cannot prove — an unknown container, a truncated header, a malformed
* size — answers false so the caller reads the whole file.
*
* NOTE this judges the HEADER window only. Trailer metadata (ID3v1, APE) is the
* caller's business — see trailerFitsInFooter.
*/
export declare function metadataFitsInHeader(header: Uint8Array, limit: number): boolean;
/**
* True when a file's TRAILER metadata provably fits in the last `footerSize`
* bytes, given `tail` — the end of the file, at least that long.
*
* Partial loading keeps the file's last `footerSize` bytes, so ID3v1 (always
* exactly 128 bytes) is safe by construction. APEv2 is not: it is unbounded
* because it can carry cover art, and an APE tag larger than the footer window
* is spliced so that TagLib computes its start inside the header window's audio
* and reads nothing. Measured: a 410 KB APE tag lost EVERY tag value silently,
* while a 41 KB one round-tripped.
*/
export declare function trailerFitsInFooter(tail: Uint8Array, footerSize: number): boolean;
//# sourceMappingURL=metadata-extent.d.ts.map