{"record":{"id":"b10f5e4d26e9b0d1","repo":"SubtitleEdit/subtitleedit","slug":"problem-reading-data-in-file-filename","errorCode":null,"errorMessage":"Problem reading data in file {FileName}","messagePattern":"Problem reading data in file (.+?)","errorType":"exception","errorClass":"RiffParserException","httpStatus":null,"severity":"error","filePath":"src/libse/ContainerFormats/RiffParser.cs","lineNumber":370,"sourceCode":"        }\n\n        /// <summary>\n        /// Read the specified length into the byte array at the specified\n        /// offset in the array\n        /// </summary>\n        /// <param name=\"data\">Array of bytes to read into</param>\n        /// <param name=\"offset\">Offset in the array to start from</param>\n        /// <param name=\"length\">Number of bytes to read</param>\n        /// <returns>Number of bytes actually read</returns>\n        public int ReadData(Byte[] data, int offset, int length)\n        {\n            try\n            {\n                return _stream.Read(data, offset, length);\n            }\n            catch (Exception ex)\n            {\n                throw new RiffParserException(\"Problem reading data in file \" + FileName, ex);\n            }\n        }\n\n        /// <summary>\n        /// Close the RIFF file\n        /// </summary>\n        public void CloseFile()\n        {\n            if (null != _stream)\n            {\n                _stream.Close();\n                _stream = null;\n            }\n        }\n\n        #endregion Stream access\n\n        #region FourCC conversion methods","sourceCodeStart":352,"sourceCodeEnd":388,"githubUrl":"https://github.com/SubtitleEdit/subtitleedit/blob/17a9f0748781032255db3526b7215d2fb891e3af/src/libse/ContainerFormats/RiffParser.cs#L352-L388","documentation":"ReadData delegates to Stream.Read for arbitrary-length chunk payloads, wrapping any exception as 'Problem reading data in file'. This is the general payload-read path used by DecodeAviHeader/DecodeAviStream and others when copying chunk bodies.","triggerScenarios":"Stream throws during a multi-byte read (I/O error, disposed stream, unreadable stream, network drop); buffer/offset/length mismatch causing ArgumentException.","commonSituations":"Disk read error mid-payload; file deleted during parse; concurrent write without FileShare; bad length passed from a corrupt chunk size.","solutions":["Inspect InnerException for the underlying I/O error.","Keep the file/stream open and readable for the parse lifetime; use FileShare.ReadWrite.","Validate chunk size before issuing the read to avoid huge/invalid lengths.","Retry the parse from a fresh stream on transient I/O."],"exampleFix":"// before\ntry { return _stream.Read(data, offset, length); }\ncatch (Exception ex) { throw new RiffParserException(\"Problem reading data in file \" + FileName, ex); }\n\n// after\ntry { return _stream.Read(data, offset, length); }\ncatch (Exception ex) { throw new RiffParserException($\"Problem reading {length}B at offset {offset} (pos {_stream?.Position}) in {FileName}\", ex); }","handlingStrategy":"try-catch","validationCode":"if (data == null) throw new ArgumentNullException(nameof(data));\nif (offset < 0 || length < 0 || offset + length > data.Length) throw new ArgumentException(\"Invalid offset/length\");\nif (!stream.CanRead) throw new NotSupportedException(\"stream must be readable\");","typeGuard":null,"tryCatchPattern":"try { rp.ReadData(buf, 0, len); }\ncatch (RiffParserException ex) { var root = ex.InnerException ?? ex; /* handle I/O root */ }","preventionTips":["Inspect InnerException for the underlying I/O error.","Keep the stream open and use FileShare.ReadWrite."],"tags":["riff","io","exception-wrap","container-format","stream-read"],"backgroundTag":null,"analyzedSha":"17a9f0748781032255db3526b7215d2fb891e3af","analyzedAt":"2026-08-13T18:11:43.374Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}