{"record":{"id":"a69227e1d378e9d4","repo":"pion/webrtc","slug":"incomplete-frame-header","errorCode":null,"errorMessage":"incomplete frame header","messagePattern":"incomplete frame header","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/media/ivfreader/ivfreader.go","lineNumber":22,"sourceCode":"// Package ivfreader implements IVF media container reader\npackage ivfreader\n\nimport (\n\t\"encoding/binary\"\n\t\"errors\"\n\t\"fmt\"\n\t\"io\"\n)\n\nconst (\n\tivfFileHeaderSignature = \"DKIF\"\n\tivfFileHeaderSize      = 32\n\tivfFrameHeaderSize     = 12\n)\n\nvar (\n\terrNilStream             = errors.New(\"stream is nil\")\n\terrIncompleteFrameHeader = errors.New(\"incomplete frame header\")\n\terrIncompleteFrameData   = errors.New(\"incomplete frame data\")\n\terrIncompleteFileHeader  = errors.New(\"incomplete file header\")\n\terrSignatureMismatch     = errors.New(\"IVF signature mismatch\")\n\terrUnknownIVFVersion     = errors.New(\"IVF version unknown, parser may not parse correctly\")\n\terrInvalidMediaTimebase  = errors.New(\"invalid media timebase\")\n)\n\n// IVFFileHeader 32-byte header for IVF files\n// https://wiki.multimedia.cx/index.php/IVF\ntype IVFFileHeader struct {\n\tsignature           string // 0-3\n\tversion             uint16 // 4-5\n\theaderSize          uint16 // 6-7\n\tFourCC              string // 8-11\n\tWidth               uint16 // 12-13\n\tHeight              uint16 // 14-15\n\tTimebaseDenominator uint32 // 16-19\n\tTimebaseNumerator   uint32 // 20-23","sourceCodeStart":4,"sourceCodeEnd":40,"githubUrl":"https://github.com/pion/webrtc/blob/8c25dc09fa9e7c09aac4309ead88093d760432b0/pkg/media/ivfreader/ivfreader.go#L4-L40","documentation":"Returned by IVFReader.ParseNextFrame when reading the 12-byte frame header ends with io.ErrUnexpectedEOF, i.e. the stream ended partway through a frame header. The IVF container stores a 12-byte header before every frame; a partial header means truncated or corrupt data.","triggerScenarios":"ParseNextFrame on a stream whose remaining bytes are between 1 and 11 when reading the frame header.","commonSituations":"Truncated downloads of IVF files, interrupted recordings, reading a file still being written, byte-range reads that cut a frame header in half.","solutions":["Treat it as end-of-truncated-stream: stop iterating and validate/repair the source file.","Re-download or re-capture the IVF file; verify integrity (checksum, duration).","If partial frames are acceptable, catch this error specifically (errors.Is / equality) and break the loop instead of failing."],"exampleFix":"// before\nfor {\n    frame, _, err := reader.ParseNextFrame()\n    if err != nil { return err }\n}\n// after\nfor {\n    frame, _, err := reader.ParseNextFrame()\n    if err != nil {\n        if err == ivfreader.ErrIncompleteFrameHeader {\n            log.Warn(\"truncated IVF file, stopping\")\n            break\n        }\n        return err\n    }\n}","handlingStrategy":"try-catch","validationCode":"fi, err := f.Stat()\nif err != nil {\n    return err\n}\nif fi.Size() < 32 {\n    return errors.New(\"file too small to contain an IVF frame\")\n}","typeGuard":null,"tryCatchPattern":"frame, hdr, err := reader.ParseNextFrame()\nif err == ivfreader.ErrIncompleteFrameHeader {\n    log.Warn(\"IVF stream truncated in frame header; stopping\")\n    return nil\n} else if err != nil {\n    return err\n}","preventionTips":["Verify file completeness (size, checksum) before parsing IVF files.","Don't parse files that are still being written or downloaded.","Treat mid-header truncation as a data-integrity problem, not a parser bug."],"tags":["go","media","ivf","truncated-data"],"backgroundTag":"truncated-input-stream","analyzedSha":"8c25dc09fa9e7c09aac4309ead88093d760432b0","analyzedAt":"2026-09-03T21:56:56.182Z","contentChangedAt":"2026-09-03T21:56:56.182Z","schemaVersion":2},"datasetVersion":"2026-09-11T07:07:21.782Z"}