{"record":{"id":"e8a0ecacc1719d5e","repo":"SubtitleEdit/subtitleedit","slug":"problem-seeking-in-file-filename","errorCode":null,"errorMessage":"Problem seeking in file {FileName}","messagePattern":"Problem seeking in file (.+?)","errorType":"exception","errorClass":"RiffParserException","httpStatus":null,"severity":"error","filePath":"src/libse/ContainerFormats/RiffParser.cs","lineNumber":350,"sourceCode":"            catch (Exception ex)\n            {\n                throw new RiffParserException(\"Problem accessing RIFF file \" + FileName, ex);\n            }\n        }\n\n        /// <summary>\n        /// Skip the specified number of bytes\n        /// </summary>\n        /// <param name=\"skipBytes\">Number of bytes to skip</param>\n        public void SkipData(int skipBytes)\n        {\n            try\n            {\n                _stream.Seek(skipBytes, SeekOrigin.Current);\n            }\n            catch (Exception ex)\n            {\n                throw new RiffParserException(\"Problem seeking in file \" + FileName, ex);\n            }\n        }\n\n        /// <summary>\n        /// Read the specified length into the byte array at the specified\n        /// offset in the array\n        /// </summary>\n        /// <param name=\"data\">Array of bytes to read into</param>\n        /// <param name=\"offset\">Offset in the array to start from</param>\n        /// <param name=\"length\">Number of bytes to read</param>\n        /// <returns>Number of bytes actually read</returns>\n        public int ReadData(Byte[] data, int offset, int length)\n        {\n            try\n            {\n                return _stream.Read(data, offset, length);\n            }\n            catch (Exception ex)","sourceCodeStart":332,"sourceCodeEnd":368,"githubUrl":"https://github.com/SubtitleEdit/subtitleedit/blob/17a9f0748781032255db3526b7215d2fb891e3af/src/libse/ContainerFormats/RiffParser.cs#L332-L368","documentation":"SkipData calls Stream.Seek to advance past unwanted bytes; any exception from Seek (ArgumentException on negative offset, IOException on a non-seekable stream, NotSupportedException on a forward-only stream) is wrapped as 'Problem seeking in file'. The parser relies on seeking to align to chunk boundaries, so unseekable streams cannot be tolerated.","triggerScenarios":"Passing a forward-only/non-seekable stream (e.g. network or decompression stream) to RiffParser; seek offset beyond stream length; disposed stream.","commonSituations":"Wrapping a GZip/Deflate stream directly without a buffering seekable layer; reading from a pipe; malicious/corrupt size producing a bad skip offset.","solutions":["Ensure the stream passed to RiffParser supports CanSeek and has the full content buffered.","Buffer forward-only streams into a MemoryStream before parsing.","Validate skipBytes is non-negative and within stream bounds before seeking.","Catch RiffParserException and report a seek failure to the user."],"exampleFix":"// before\ntry { _stream.Seek(skipBytes, SeekOrigin.Current); }\ncatch (Exception ex) { throw new RiffParserException(\"Problem seeking in file \" + FileName, ex); }\n\n// after\nif (!_stream.CanSeek) throw new NotSupportedException($\"RIFF parser requires a seekable stream ({FileName}).\");\nif (skipBytes < 0) throw new ArgumentOutOfRangeException(nameof(skipBytes));\ntry { _stream.Seek(skipBytes, SeekOrigin.Current); }\ncatch (Exception ex) { throw new RiffParserException($\"Problem seeking {skipBytes}B in {FileName}\", ex); }","handlingStrategy":"validation","validationCode":"if (stream == null) throw new ArgumentNullException(nameof(stream));\nif (!stream.CanSeek) throw new NotSupportedException(\"RIFF parser requires a seekable stream.\");\nif (skipBytes < 0 || stream.Position + skipBytes > stream.Length) throw new ArgumentOutOfRangeException(nameof(skipBytes));","typeGuard":"static bool CanParseRiff(Stream s) => s != null && s.CanRead && s.CanSeek;","tryCatchPattern":"try { rp.SkipData(n); }\ncatch (RiffParserException ex) when (ex.Message.Contains(\"seeking\")) { /* non-seekable or out of range */ }","preventionTips":["Buffer forward-only streams into a MemoryStream before parsing.","Verify CanSeek before constructing RiffParser."],"tags":["riff","seek","stream","container-format","non-seekable"],"backgroundTag":null,"analyzedSha":"17a9f0748781032255db3526b7215d2fb891e3af","analyzedAt":"2026-08-13T18:11:43.374Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}