Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS
JavaScript ai-agentsdashboarddeveloper-toolsdigital-twinquantified-selfsecond-brainself-hostedtailscale
fix: read the full post-ID3 probe window when a manifest crosses the first read boundary (#12539)
[._.]/ Adam Eivya21f63b46b75
diff --git a/server/lib/uploads.js b/server/lib/uploads.jsindex 385fb9e95a..1985fb0052 100644--- a/server/lib/uploads.js+++ b/server/lib/uploads.js@@ -28,8 +28,10 @@ function assertNotMediaManifest(buffer) {}/**- * `assertNotMediaManifest` over a file on disk: its leading window, plus the- * window after an ID3v2 tag too long to fit in it.+ * `assertNotMediaManifest` over a file on disk: its leading window, plus a+ * full window after an ID3v2 tag. A tag ending inside a full leading window+ * leaves only a fragment of the following manifest in it, so the post-tag+ * window is read whenever the leading read filled its buffer.*/export async function assertFileNotMediaManifest(path) {const handle = await open(path, 'r');@@ -41,7 +43,7 @@ export async function assertFileNotMediaManifest(path) {const windows = await (async () => {const head = await readWindow(0);const tagLength = id3v2TagLength(head);- return tagLength >= head.length && head.length === MEDIA_MANIFEST_PROBE_BYTES ? [head, await readWindow(tagLength)] : [head];+ return tagLength > 0 && head.length === MEDIA_MANIFEST_PROBE_BYTES ? [head, await readWindow(tagLength)] : [head];})().finally(() => handle.close());for (const window of windows) assertNotMediaManifest(window);}diff --git a/server/routes/uploads.test.js b/server/routes/uploads.test.jsindex 79c114f057..3aa933f1ed 100644--- a/server/routes/uploads.test.js+++ b/server/routes/uploads.test.js@@ -234,4 +234,36 @@ describe('streamed uploads', () => {// The same text under a non-media extension never reaches ffmpeg.expect((await post(buildApp(), 'playlist-notes.txt', playlist)).status).toBe(200);});++ // ffmpeg strips a leading ID3v2 tag before probing, so a playlist behind a tag+ // is read as HLS; the disk window after the tag must be complete wherever the+ // tag ends relative to the first 1 MiB read.+ it('refuses a playlist behind an ID3v2 tag on either side of the first probe window and accepts binary audio there', async () => {+ const MiB = 1 << 20;+ const withTag = (tagLength, payload) => {+ const header = Buffer.alloc(10);+ header.write('ID3');+ header[3] = 3;+ const size = tagLength - 10;+ header[6] = (size >> 21) & 0x7f;+ header[7] = (size >> 14) & 0x7f;+ header[8] = (size >> 7) & 0x7f;+ header[9] = size & 0x7f;+ return Buffer.concat([header, Buffer.alloc(tagLength - 10), payload]);+ };+ const playlist = Buffer.from('#EXTM3U\n#EXTINF:2.0,\n../private/clip.mp4\n#EXT-X-ENDLIST\n');+ const audio = Buffer.concat([Buffer.from([0xff, 0xfb, 0x90, 0x00, 0x00]), Buffer.alloc(4096, 0x41)]);+ const upload = (bytes) => request(buildApp()).post('/api/uploads')+ .set('Content-Type', 'multipart/form-data; boundary=upload-test').send(multipart('tagged.mp3', bytes));++ // One byte short of the boundary leaves only '#' of the playlist inside the first read.+ for (const tagLength of [MiB - 1, MiB, MiB + 4096]) {+ const res = await upload(withTag(tagLength, playlist));+ expect(res.status, `tag length ${tagLength}`).toBe(400);+ expect(res.body.code).toBe('INVALID_FILE_TYPE');+ }+ for (const tagLength of [MiB - 1, MiB + 4096]) {+ expect((await upload(withTag(tagLength, audio))).status, `tag length ${tagLength}`).toBe(200);+ }+ });});