SubtitleEdit/subtitleedit · error · RiffParserException

Problem seeking in file

Error message

Problem seeking in file {FileName}

What it means

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.

Solutions

  1. Ensure the stream passed to RiffParser supports CanSeek and has the full content buffered.
  2. Buffer forward-only streams into a MemoryStream before parsing.
  3. Validate skipBytes is non-negative and within stream bounds before seeking.
  4. Catch RiffParserException and report a seek failure to the user.

Example fix

// before
try { _stream.Seek(skipBytes, SeekOrigin.Current); }
catch (Exception ex) { throw new RiffParserException("Problem seeking in file " + FileName, ex); }

// after
if (!_stream.CanSeek) throw new NotSupportedException($"RIFF parser requires a seekable stream ({FileName}).");
if (skipBytes < 0) throw new ArgumentOutOfRangeException(nameof(skipBytes));
try { _stream.Seek(skipBytes, SeekOrigin.Current); }
catch (Exception ex) { throw new RiffParserException($"Problem seeking {skipBytes}B in {FileName}", ex); }
Defensive patterns

Strategy: validation

Validate before calling

if (stream == null) throw new ArgumentNullException(nameof(stream));
if (!stream.CanSeek) throw new NotSupportedException("RIFF parser requires a seekable stream.");
if (skipBytes < 0 || stream.Position + skipBytes > stream.Length) throw new ArgumentOutOfRangeException(nameof(skipBytes));

Type guard

static bool CanParseRiff(Stream s) => s != null && s.CanRead && s.CanSeek;

Try / catch

try { rp.SkipData(n); }
catch (RiffParserException ex) when (ex.Message.Contains("seeking")) { /* non-seekable or out of range */ }

Prevention

When it happens

Trigger: Passing a forward-only/non-seekable stream (e.g. network or decompression stream) to RiffParser; seek offset beyond stream length; disposed stream.

Common situations: Wrapping a GZip/Deflate stream directly without a buffering seekable layer; reading from a pipe; malicious/corrupt size producing a bad skip offset.

Related errors


AI-assisted analysis of SubtitleEdit/subtitleedit@17a9f07487 (2026-08-13). Data as JSON: /api/errors/e8a0ecacc1719d5e. Report an issue: GitHub.

Appendix: source

Thrown at src/libse/ContainerFormats/RiffParser.cs:350

            catch (Exception ex)
            {
                throw new RiffParserException("Problem accessing RIFF file " + FileName, ex);
            }
        }

        /// <summary>
        /// Skip the specified number of bytes
        /// </summary>
        /// <param name="skipBytes">Number of bytes to skip</param>
        public void SkipData(int skipBytes)
        {
            try
            {
                _stream.Seek(skipBytes, SeekOrigin.Current);
            }
            catch (Exception ex)
            {
                throw new RiffParserException("Problem seeking in file " + FileName, ex);
            }
        }

        /// <summary>
        /// Read the specified length into the byte array at the specified
        /// offset in the array
        /// </summary>
        /// <param name="data">Array of bytes to read into</param>
        /// <param name="offset">Offset in the array to start from</param>
        /// <param name="length">Number of bytes to read</param>
        /// <returns>Number of bytes actually read</returns>
        public int ReadData(Byte[] data, int offset, int length)
        {
            try
            {
                return _stream.Read(data, offset, length);
            }
            catch (Exception ex)

View on GitHub (pinned to 17a9f07487)