{"record":{"id":"7c56a2bb81440098","repo":"sxyazi/yazi","slug":"invalidinput-7c56a2","errorCode":"InvalidInput","errorMessage":"seek overflow","messagePattern":"seek overflow","errorType":"exception","errorClass":"io::Error","httpStatus":null,"severity":"error","filePath":"yazi-vfs/src/engine/lua/file.rs","lineNumber":147,"sourceCode":"\t\t\tme.pos = me.pos.checked_add(n as u64).expect(\"offset overflow\");\n\t\t}))\n\t}\n}\n\nimpl AsyncSeek for File {\n\tfn start_seek(self: Pin<&mut Self>, position: SeekFrom) -> io::Result<()> {\n\t\tlet me = self.get_mut();\n\t\tif me.pending_seek.is_some() {\n\t\t\treturn Err(io::Error::other(\"call poll_complete before start_seek\"));\n\t\t}\n\n\t\tme.pending_seek = Some(match position {\n\t\t\tSeekFrom::Start(n) => SeekState::NonBlocking(n),\n\t\t\tSeekFrom::Current(n) => me\n\t\t\t\t.pos\n\t\t\t\t.checked_add_signed(n)\n\t\t\t\t.map(SeekState::NonBlocking)\n\t\t\t\t.ok_or_else(|| io::Error::new(io::ErrorKind::InvalidInput, \"seek overflow\"))?,\n\t\t\tSeekFrom::End(n) => {\n\t\t\t\tlet service = me.service;\n\t\t\t\tlet job = ProvideJob::Metadata { url: me.url.clone() };\n\t\t\t\tSeekState::Blocking(\n\t\t\t\t\tn,\n\t\t\t\t\tBox::pin(async move { Ok(RUNNER.provide::<Cha>(service, job).await.0?.len) }),\n\t\t\t\t)\n\t\t\t}\n\t\t});\n\n\t\tOk(())\n\t}\n\n\tfn poll_complete(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<io::Result<u64>> {\n\t\tlet me = self.get_mut();\n\t\tlet Some(state) = &mut me.pending_seek else {\n\t\t\treturn Poll::Ready(Ok(me.pos));\n\t\t};","sourceCodeStart":129,"sourceCodeEnd":165,"githubUrl":"https://github.com/sxyazi/yazi/blob/5f901b886b14de1f17460b6e52e9de5d67f8aba9/yazi-vfs/src/engine/lua/file.rs#L129-L165","documentation":"This error is raised by the Lua file handle's seek implementation when computing a new absolute position from `SeekFrom::Current(n)` overflows (or underflows) the internal position counter via `checked_add_signed`. The seek is rejected before any I/O so the handle's position is never left in an invalid state. It means the requested relative offset is nonsensical for the current position.","triggerScenarios":"Calling `file:seek('cur', n)` from Lua (or `Seek(SeekFrom::Current(n))` on the handle) where `pos + n` overflows i64/u64 — e.g. a huge positive offset past the file end or a negative offset larger than the current position that underflows below 0.","commonSituations":"Scripts computing offsets from untrusted/erroneous data (bad chunk sizes, corrupt metadata), seeking backwards with a negative delta larger than the current position, or off-by-one loops that keep advancing a cursor indefinitely.","solutions":["Check the current position (`seek('cur', 0)`) before applying a relative offset and clamp n so `pos + n >= 0`","Use `SeekFrom::Start(n)` with an absolute, validated offset instead of a relative Current seek","Fix the logic that computes the delta; negative seeks below position 0 are invalid","Catch the io::Error with ErrorKind::InvalidInput and surface a clear message to the user"],"exampleFix":"-- before\nfile:seek('cur', -huge_offset) -- underflows\n-- after\nlocal pos = file:seek('cur', 0)\nlocal delta = math.min(huge_offset, pos)\nfile:seek('cur', -delta)","handlingStrategy":"validation","validationCode":"local pos = file:seek('cur', 0)\nassert(pos + delta >= 0, 'seek underflow: delta too negative for pos '..pos)","typeGuard":null,"tryCatchPattern":"local ok, err = pcall(function() return file:seek('cur', delta) end)\nif not ok then\n  -- err: seek overflow (InvalidInput)\n  file:seek('set', 0) -- reset to a known-good position\nend","preventionTips":["Prefer absolute seeks (SeekFrom::Start) over relative Current seeks with computed deltas","Read the current position with seek('cur', 0) before applying relative offsets","Clamp computed offsets against file size and current position","Validate delta sources (chunk sizes, metadata) before using them as seek offsets"],"tags":["io","seek","overflow","lua"],"backgroundTag":"seek-position-overflow","analyzedSha":"5f901b886b14de1f17460b6e52e9de5d67f8aba9","analyzedAt":"2026-09-02T18:38:25.566Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}