SubtitleEdit/subtitleedit · error · RiffParserException

Problem reading data in file {FileName}

Error message

Problem reading data in file {FileName}

What it means

ReadData delegates to Stream.Read for arbitrary-length chunk payloads, wrapping any exception as 'Problem reading data in file'. This is the general payload-read path used by DecodeAviHeader/DecodeAviStream and others when copying chunk bodies.

Source

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

        }

        /// <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)
            {
                throw new RiffParserException("Problem reading data in file " + FileName, ex);
            }
        }

        /// <summary>
        /// Close the RIFF file
        /// </summary>
        public void CloseFile()
        {
            if (null != _stream)
            {
                _stream.Close();
                _stream = null;
            }
        }

        #endregion Stream access

        #region FourCC conversion methods

View on GitHub (pinned to 17a9f07487)

Solutions

  1. Inspect InnerException for the underlying I/O error.
  2. Keep the file/stream open and readable for the parse lifetime; use FileShare.ReadWrite.
  3. Validate chunk size before issuing the read to avoid huge/invalid lengths.
  4. Retry the parse from a fresh stream on transient I/O.

Example fix

// before
try { return _stream.Read(data, offset, length); }
catch (Exception ex) { throw new RiffParserException("Problem reading data in file " + FileName, ex); }

// after
try { return _stream.Read(data, offset, length); }
catch (Exception ex) { throw new RiffParserException($"Problem reading {length}B at offset {offset} (pos {_stream?.Position}) in {FileName}", ex); }
Defensive patterns

Strategy: try-catch

Validate before calling

if (data == null) throw new ArgumentNullException(nameof(data));
if (offset < 0 || length < 0 || offset + length > data.Length) throw new ArgumentException("Invalid offset/length");
if (!stream.CanRead) throw new NotSupportedException("stream must be readable");

Try / catch

try { rp.ReadData(buf, 0, len); }
catch (RiffParserException ex) { var root = ex.InnerException ?? ex; /* handle I/O root */ }

Prevention

When it happens

Trigger: Stream throws during a multi-byte read (I/O error, disposed stream, unreadable stream, network drop); buffer/offset/length mismatch causing ArgumentException.

Common situations: Disk read error mid-payload; file deleted during parse; concurrent write without FileShare; bad length passed from a corrupt chunk size.

Related errors


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