SubtitleEdit/subtitleedit · error · RiffParserException
Problem reading AVI header.
Error message
Problem reading AVI header.
What it means
DecodeAviHeader reads 'length' bytes for the AVIMAINHEADER chunk via RiffParser.ReadData; if fewer than 'length' bytes are returned the main AVI header is incomplete and cannot be decoded, so a RiffParserException is thrown. The downstream fields (frame rate, dimensions, stream count) all depend on a complete 56-byte header.
Source
Thrown at src/libse/ContainerFormats/RiffDecodeHeader.cs:243
public static short GetShort(byte[] buffer, int index)
{
byte[] bytes = { buffer[index + 0], buffer[index + 1] };
if (!BitConverter.IsLittleEndian)
{
Array.Reverse(bytes);
}
return BitConverter.ToInt16(bytes, 0);
}
private void DecodeAviHeader(RiffParser rp, int length)
{
var ba = new byte[length];
if (rp.ReadData(ba, 0, length) != length)
{
throw new RiffParserException("Problem reading AVI header.");
}
_frameRate = GetInt(ba, 0);
_maxBitRate = GetInt(ba, 4);
_totalFrames = GetInt(ba, 16);
_numStreams = GetInt(ba, 24);
_width = GetInt(ba, 32);
_height = GetInt(ba, 36);
}
private void DecodeAviStream(RiffParser rp, int length)
{
var ba = new byte[length];
if (rp.ReadData(ba, 0, length) != length)
{
throw new RiffParserException("Problem reading AVI header.");
}
View on GitHub (pinned to 17a9f07487)
Solutions
- Re-acquire the full AVI file from source.
- Before decoding, validate the declared 'avih' size is at least 56 bytes and matches remaining stream bytes.
- Catch RiffParserException and report a corrupt-file error to the user.
- Use a different container parser as a cross-check if the file must be salvaged.
Example fix
// before
var ba = new byte[length];
if (rp.ReadData(ba, 0, length) != length) throw new RiffParserException("Problem reading AVI header.");
// after
var ba = new byte[length];
int got = rp.ReadData(ba, 0, length);
if (got != length) throw new RiffParserException($"Short AVI header: read {got} of {length} bytes"); Defensive patterns
Strategy: try-catch
Validate before calling
if (length < 56 || rp.BytesRemaining < length) throw new InvalidDataException($"AVI main header too short: {length}B"); Try / catch
try { header.DecodeAviHeader(rp, length); }
catch (RiffParserException ex) when (ex.Message.Contains("AVI header")) { /* corrupt; bail or salvage */ } Prevention
- Re-acquire AVI from source when the main header is short.
- Pre-validate 'avih' chunk size before decoding.
When it happens
Trigger: AVI file truncated inside the 'avih' chunk; RIFF nesting where the declared chunk size exceeds remaining data; RiffParser handed a stream positioned past the header.
Common situations: Partially downloaded AVI; AVI produced by a buggy encoder that wrote a short 'avih'; file written but not flushed/closed properly.
Related errors
- Element size mismatch for element {FromFourCc(fourCc)} need
- Unable to read. Corrupt RIFF file {FileName}
- MXF KLV packet - stream does not have 16 bytes available for
- Problem accessing RIFF file {FileName}
- Problem seeking in file {FileName}
AI-assisted analysis of SubtitleEdit/subtitleedit@17a9f07487 (2026-08-13).
Data as JSON: /api/errors/0192707f87c4e47a.
Report an issue: GitHub.