{"record":{"id":"601fdb7035fe9588","repo":"remotion-dev/remotion","slug":"seeking-infinite-loop-detected-seeked-to-byte-0x","errorCode":null,"errorMessage":"Seeking infinite loop detected: Seeked to byte 0x${byte.toString(16)} ${lastSeek.numberOfTimes} times in a row in the last 2 seconds. Check your usage of .seek().","messagePattern":"Seeking infinite loop detected: Seeked to byte 0x(.+?) (.+?) times in a row in the last 2 seconds\\. Check your usage of \\.seek\\(\\)\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/media-parser/src/state/seek-infinite-loop.ts","lineNumber":26,"sourceCode":"\tlet firstSeekTime: number | null = null;\n\n\treturn {\n\t\tregisterSeek: (byte: number) => {\n\t\t\tconst now = Date.now();\n\n\t\t\tif (!lastSeek || lastSeek.byte !== byte) {\n\t\t\t\tlastSeek = {byte, numberOfTimes: 1};\n\t\t\t\tfirstSeekTime = now;\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tlastSeek.numberOfTimes++;\n\t\t\tif (\n\t\t\t\tlastSeek.numberOfTimes >= 10 &&\n\t\t\t\tfirstSeekTime &&\n\t\t\t\tnow - firstSeekTime <= 2000\n\t\t\t) {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t`Seeking infinite loop detected: Seeked to byte 0x${byte.toString(16)} ${lastSeek.numberOfTimes} times in a row in the last 2 seconds. Check your usage of .seek().`,\n\t\t\t\t);\n\t\t\t}\n\n\t\t\tif (now - (firstSeekTime as number) > 2000) {\n\t\t\t\tlastSeek = {byte, numberOfTimes: 1};\n\t\t\t\tfirstSeekTime = now;\n\t\t\t}\n\t\t},\n\t\treset: () => {\n\t\t\tlastSeek = null;\n\t\t\tfirstSeekTime = null;\n\t\t},\n\t};\n};\n\nexport type SeekInfiniteLoop = ReturnType<\n\ttypeof seekInfiniteLoopDetectionState","sourceCodeStart":8,"sourceCodeEnd":44,"githubUrl":"https://github.com/remotion-dev/remotion/blob/78fe4bb3fdb5a2cd68724393d63cb223db333fa7/packages/media-parser/src/state/seek-infinite-loop.ts#L8-L44","documentation":"Thrown by the seek-state guard when the same byte offset is seeked to at least 10 times within a 2-second window. It detects pathological seek loops (typically caused by malformed media or parser bugs) that would otherwise spin forever, and aborts them with an actionable message pointing at .seek() usage.","triggerScenarios":"A container whose structure causes the parser to repeatedly seek to the identical offset (circular box references, corrupt offset tables, a malformed index). Also triggered by custom parser extensions that misuse the seek API in a tight loop.","commonSituations":"Parsing a corrupt or truncated mp4/mov where stco/stsz tables point back to the same location. Hand-crafted test media with cyclic offsets. A controller/seek hook that always re-seeks to the same byte after each read.","solutions":["Validate the media file with a tool like ffprobe before parsing; re-mux or re-download if it reports errors.","If you control seek calls, ensure seeks advance based on parsed offsets rather than a fixed position.","Catch the error to degrade gracefully and report the problematic media to the user."],"exampleFix":"// before\ncontroller._internals.seekTo(fixedByte); // called in a loop\n\n// after\nlet advanced = computeNextOffset(lastParsedBox);\ncontroller._internals.seekTo(advanced);","handlingStrategy":"try-catch","validationCode":"// Pre-validate with ffprobe (Node) before parseMedia\nimport { execSync } from 'node:child_process';\nfunction isValidMedia(p: string): boolean { try { execSync(`ffprobe -v error \"${p}\"`, { stdio: 'ignore' }); return true; } catch { return false; } }","typeGuard":null,"tryCatchPattern":"try { await parseMedia({ src, fields }); } catch (e) { if (/Seeking infinite loop detected/.test(String((e as Error).message))) { /* reject corrupt media, re-mux, or skip */ } else throw e; }","preventionTips":["Validate media integrity with ffprobe before parsing.","Re-mux corrupt or non-standard media into a clean container.","Avoid custom seek hooks that re-seek to a fixed offset."],"tags":["media-parser","seek","infinite-loop","corrupt-file","guard"],"backgroundTag":null,"analyzedSha":"78fe4bb3fdb5a2cd68724393d63cb223db333fa7","analyzedAt":"2026-08-12T17:18:50.444Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}