{"record":{"id":"bbcf969964277fc8","repo":"SubtitleEdit/subtitleedit","slug":"unable-to-read-corrupt-riff-file-filename","errorCode":null,"errorMessage":"Unable to read. Corrupt RIFF file {FileName}","messagePattern":"Unable to read\\. Corrupt RIFF file (.+?)","errorType":"exception","errorClass":"RiffParserException","httpStatus":null,"severity":"error","filePath":"src/libse/ContainerFormats/RiffParser.cs","lineNumber":305,"sourceCode":"        }\n\n        #region Stream access\n\n        /// <summary>\n        /// Non-thread-safe method to read two ints from the stream\n        /// </summary>\n        /// <param name=\"fourCc\">Output FourCC int</param>\n        /// <param name=\"size\">Output chunk/list size</param>\n        public void ReadTwoInts(out int fourCc, out int size)\n        {\n            try\n            {\n                var buffer = new byte[TwoDWordSize];\n                int readsize = _stream.Read(buffer, 0, TwoDWordSize);\n\n                if (TwoDWordSize != readsize)\n                {\n                    throw new RiffParserException(\"Unable to read. Corrupt RIFF file \" + FileName);\n                }\n                fourCc = RiffDecodeHeader.GetInt(buffer, 0);\n                size = RiffDecodeHeader.GetInt(buffer, 4);\n            }\n            catch (Exception ex)\n            {\n                throw new RiffParserException(\"Problem accessing RIFF file \" + FileName, ex);\n            }\n        }\n\n        /// <summary>\n        /// Non-thread-safe read a single int from the stream\n        /// </summary>\n        /// <param name=\"fourCc\">Output int</param>\n        public void ReadOneInt(out int fourCc)\n        {\n            try\n            {","sourceCodeStart":287,"sourceCodeEnd":323,"githubUrl":"https://github.com/SubtitleEdit/subtitleedit/blob/17a9f0748781032255db3526b7215d2fb891e3af/src/libse/ContainerFormats/RiffParser.cs#L287-L323","documentation":"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.","triggerScenarios":"Reaching EOF while reading a chunk header; truncated RIFF file; stream position advanced past real data.","commonSituations":"Truncated download; AVI/WAV cut mid-write; stream wrapping a buffer that ended unexpectedly.","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."],"exampleFix":"// before\nint readsize = _stream.Read(buffer, 0, TwoDWordSize);\nif (TwoDWordSize != readsize) throw new RiffParserException(\"Unable to read. Corrupt RIFF file \" + FileName);\n\n// after\nint readsize = _stream.Read(buffer, 0, TwoDWordSize);\nif (TwoDWordSize != readsize) throw new RiffParserException($\"Short RIFF read at {_stream.Position}: got {readsize} of {TwoDWordSize} bytes in {FileName}\");","handlingStrategy":"try-catch","validationCode":"if (!stream.CanRead || stream.Length - stream.Position < 8) throw new InvalidDataException(\"Fewer than 8 bytes remain for a RIFF int pair\");","typeGuard":null,"tryCatchPattern":"try { rp.ReadTwoInts(out fcc, out size); }\ncatch (RiffParserException ex) when (ex.Message.Contains(\"Corrupt RIFF\")) { /* treat as EOF when iterating */ }","preventionTips":["Check remaining bytes before each header read.","Validate the top-level RIFF signature first."],"tags":["riff","container-format","truncated","stream-read"],"backgroundTag":null,"analyzedSha":"17a9f0748781032255db3526b7215d2fb891e3af","analyzedAt":"2026-08-13T18:11:43.374Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}