SubtitleEdit/subtitleedit · error · RiffParserException
Problem accessing RIFF file {FileName}
Error message
Problem accessing RIFF file {FileName} What it means
The catch-all in ReadTwoInts wraps any exception (IOException, ObjectDisposedException, NotSupportedException from a non-readable stream, etc.) raised during the 8-byte read into a RiffParserException with the 'Problem accessing RIFF file' message and the original as inner. It surfaces stream-level failures with the file name for context.
Source
Thrown at src/libse/ContainerFormats/RiffParser.cs:312
/// <param name="fourCc">Output FourCC int</param>
/// <param name="size">Output chunk/list size</param>
public void ReadTwoInts(out int fourCc, out int size)
{
try
{
var buffer = new byte[TwoDWordSize];
int readsize = _stream.Read(buffer, 0, TwoDWordSize);
if (TwoDWordSize != readsize)
{
throw new RiffParserException("Unable to read. Corrupt RIFF file " + FileName);
}
fourCc = RiffDecodeHeader.GetInt(buffer, 0);
size = RiffDecodeHeader.GetInt(buffer, 4);
}
catch (Exception ex)
{
throw new RiffParserException("Problem accessing RIFF file " + FileName, ex);
}
}
/// <summary>
/// Non-thread-safe read a single int from the stream
/// </summary>
/// <param name="fourCc">Output int</param>
public void ReadOneInt(out int fourCc)
{
try
{
var buffer = new byte[DWordSize];
int readsize = _stream.Read(buffer, 0, DWordSize);
if (DWordSize != readsize)
{
throw new RiffParserException("Unable to read. Corrupt RIFF file " + FileName);
}
fourCc = RiffDecodeHeader.GetInt(buffer, 0);View on GitHub (pinned to 17a9f07487)
Solutions
- Inspect the InnerException to find the real I/O cause.
- Ensure the stream stays open and readable for the parser's lifetime (do not dispose prematurely).
- Open the file with FileShare.ReadWrite to avoid lock contention.
- Retry the whole parse once on transient I/O errors.
Example fix
// before
catch (Exception ex) { throw new RiffParserException("Problem accessing RIFF file " + FileName, ex); }
// after
catch (Exception ex) when (!(ex is RiffParserException)) { throw new RiffParserException($"Problem accessing RIFF file {FileName} at {_stream?.Position}", ex); } Defensive patterns
Strategy: try-catch
Validate before calling
if (stream == null) throw new ArgumentNullException(nameof(stream));
if (!stream.CanRead) throw new ArgumentException("stream must be readable", nameof(stream)); Try / catch
try { rp.ReadTwoInts(out fcc, out size); }
catch (RiffParserException ex) { var root = ex.InnerException ?? ex; /* handle I/O root */ } Prevention
- Inspect InnerException for the true cause.
- Keep the stream open and readable for the parser lifetime.
When it happens
Trigger: Underlying stream throws (closed/disposed, network drop, unreadable stream, security/permission denial); disk error during read.
Common situations: Network share disconnect mid-read; file deleted or locked by another process during parse; stream wrapped over a closed resource.
Related errors
- Problem reading data in file {FileName}
- Unable to read. Corrupt RIFF file {FileName}
- Problem reading AVI header.
- Element size mismatch for element {FromFourCc(fourCc)} need
- Problem seeking in file {FileName}
AI-assisted analysis of SubtitleEdit/subtitleedit@17a9f07487 (2026-08-13).
Data as JSON: /api/errors/4a6963bdcb94276f.
Report an issue: GitHub.