SubtitleEdit/subtitleedit · error · RiffParserException
Element size mismatch for element {FromFourCc(fourCc)} need
Error message
Element size mismatch for element {FromFourCc(fourCc)} need {size} but have only {bytesleft} What it means
While descending the RIFF tree, RiffParser computed the remaining bytes in the current scope, then compared them to the chunk/list size just read. If the declared size exceeds the bytes remaining, the data is inconsistent; the parser skips the remaining bytes (to resync) and throws RiffParserException. This is the canonical 'file lies about chunk size' guard.
Source
Thrown at src/libse/ContainerFormats/RiffParser.cs:240
return false;
}
// We have enough bytes, read
int fourCc;
int size;
ReadTwoInts(out fourCc, out size);
// Reduce bytes left
bytesleft -= TwoDWordSize;
// Do we have enough bytes?
if (bytesleft < size)
{
// Skip the bad data and throw an exception
SkipData(bytesleft);
bytesleft = 0;
throw new RiffParserException("Element size mismatch for element " + FromFourCc(fourCc)
+ " need " + size + " but have only " + bytesleft);
}
// Examine the element, is it a list or a chunk
string type = FromFourCc(fourCc);
if (type == List4Cc)
{
// We have a list
ReadOneInt(out fourCc);
if (null == list)
{
SkipData(size - 4);
}
else
{
// Invoke the list method
list(this, fourCc, size - 4);View on GitHub (pinned to 17a9f07487)
Solutions
- Re-acquire the file from source; an inconsistent RIFF tree cannot be safely parsed.
- Catch RiffParserException at the format-detection level and try alternate container formats.
- Pre-validate by reading the top-level RIFF size and comparing to file length.
- Use a tolerant parser that skips the bad chunk if salvage is required.
Example fix
// before
if (bytesleft < size) { SkipData(bytesleft); bytesleft = 0; throw new RiffParserException("Element size mismatch..."); }
// after
if (bytesleft < size) { SkipData(bytesleft); bytesleft = 0; throw new RiffParserException($"Element {FromFourCc(fourCc)} declared {size}B but only {bytesleft}B remain in scope"); } Defensive patterns
Strategy: try-catch
Validate before calling
if (size > bytesleft) throw new InvalidDataException($"Chunk {FromFourCc(fourCc)} size {size} exceeds remaining {bytesleft}"); Try / catch
try { rp.ReadElement(...); }
catch (RiffParserException ex) when (ex.Message.Contains("size mismatch")) { /* corrupt RIFF; abort */ } Prevention
- Compare top-level RIFF size to file length before parsing.
- Treat any size mismatch as unrecoverable corruption.
When it happens
Trigger: A RIFF chunk/list declares a size larger than the enclosing scope; nested LIST size inconsistent with parent; truncated file where the final chunk's size header was written but data was cut.
Common situations: AVI/WAV produced by a buggy muxer; file partially overwritten; concatenated RIFF fragments without size fixup.
Related errors
- Problem reading AVI header.
- Unable to read. Corrupt RIFF file {FileName}
- Problem accessing RIFF file {FileName}
- Problem seeking in file {FileName}
- Problem reading data in file {FileName}
AI-assisted analysis of SubtitleEdit/subtitleedit@17a9f07487 (2026-08-13).
Data as JSON: /api/errors/d0ed3baafad48b4b.
Report an issue: GitHub.