SubtitleEdit/subtitleedit · error · RiffParserException
Unable to read. Corrupt RIFF file {FileName}
Error message
Unable to read. Corrupt RIFF file {FileName} What it means
ReadTwoInts reads 8 bytes (TwoDWordSize) to get a FourCC+size pair; if Stream.Read returns fewer than 8 bytes the RIFF structure is incomplete and RiffParserException is thrown. The catch around it wraps any inner exception as 'Problem accessing RIFF file'. This guards the inner loop of RIFF traversal.
Source
Thrown at src/libse/ContainerFormats/RiffParser.cs:305
}
#region Stream access
/// <summary>
/// Non-thread-safe method to read two ints from the stream
/// </summary>
/// <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
{View on GitHub (pinned to 17a9f07487)
Solutions
- Check stream.Length - stream.Position >= 8 before calling ReadTwoInts.
- Catch RiffParserException and treat as end-of-RIFF when iterating sequentially.
- Verify the top-level 'RIFF'+size+form header before descending.
- Re-acquire the source file.
Example fix
// before
int readsize = _stream.Read(buffer, 0, TwoDWordSize);
if (TwoDWordSize != readsize) throw new RiffParserException("Unable to read. Corrupt RIFF file " + FileName);
// after
int readsize = _stream.Read(buffer, 0, TwoDWordSize);
if (TwoDWordSize != readsize) throw new RiffParserException($"Short RIFF read at {_stream.Position}: got {readsize} of {TwoDWordSize} bytes in {FileName}"); Defensive patterns
Strategy: try-catch
Validate before calling
if (!stream.CanRead || stream.Length - stream.Position < 8) throw new InvalidDataException("Fewer than 8 bytes remain for a RIFF int pair"); Try / catch
try { rp.ReadTwoInts(out fcc, out size); }
catch (RiffParserException ex) when (ex.Message.Contains("Corrupt RIFF")) { /* treat as EOF when iterating */ } Prevention
- Check remaining bytes before each header read.
- Validate the top-level RIFF signature first.
When it happens
Trigger: Reaching EOF while reading a chunk header; truncated RIFF file; stream position advanced past real data.
Common situations: Truncated download; AVI/WAV cut mid-write; stream wrapping a buffer that ended unexpectedly.
Related errors
- Problem reading AVI header.
- Problem accessing RIFF file {FileName}
- Problem reading data in file {FileName}
- MXF KLV packet - stream does not have 16 bytes available for
- Element size mismatch for element {FromFourCc(fourCc)} need
AI-assisted analysis of SubtitleEdit/subtitleedit@17a9f07487 (2026-08-13).
Data as JSON: /api/errors/bbcf969964277fc8.
Report an issue: GitHub.