{"record":{"id":"3115349faeecbf25","repo":"pion/webrtc","slug":"bad-header-signature","errorCode":null,"errorMessage":"bad header signature","messagePattern":"bad header signature","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/media/oggreader/oggreader.go","lineNumber":25,"sourceCode":"import (\n\t\"encoding/binary\"\n\t\"errors\"\n\t\"fmt\"\n\t\"io\"\n\t\"strings\"\n)\n\nconst (\n\tpageHeaderTypeBeginningOfStream = 0x02\n\tpageHeaderSignature             = \"OggS\"\n\n\tidPageBasePayloadLength = 19\n\tpageHeaderLen           = 27\n)\n\nvar (\n\terrNilStream                       = errors.New(\"stream is nil\")\n\terrBadIDPageSignature              = errors.New(\"bad header signature\")\n\terrBadOpusTagsSignature            = errors.New(\"bad opus tags signature\")\n\terrBadIDPageType                   = errors.New(\"wrong header, expected beginning of stream\")\n\terrBadIDPageLength                 = errors.New(\"payload for id page must be 19 bytes\")\n\terrBadIDPagePayloadSignature       = errors.New(\"bad payload signature\")\n\terrShortPageHeader                 = errors.New(\"not enough data for payload header\")\n\terrChecksumMismatch                = errors.New(\"expected and actual checksum do not match\")\n\terrUnsupportedChannelMappingFamily = errors.New(\"unsupported channel mapping family\")\n)\n\n// OggReader is used to read Ogg files and return page payloads.\ntype OggReader struct {\n\tstream               io.Reader\n\tbytesReadSuccesfully int64\n\tchecksumTable        *[256]uint32\n\tdoChecksum           bool\n}\n\n// OggHeader contains Opus codec metadata parsed from an Opus ID page.","sourceCodeStart":7,"sourceCodeEnd":43,"githubUrl":"https://github.com/pion/webrtc/blob/8c25dc09fa9e7c09aac4309ead88093d760432b0/pkg/media/oggreader/oggreader.go#L7-L43","documentation":"errBadIDPageSignature is returned when the first Ogg page header does not begin with the required 4-byte 'OggS' capture signature. The reader validates the ID page header via validateOpusPageHeader and rejects anything that is not a valid Ogg stream start. It means the input is not a well-formed Ogg file (or the stream is misaligned).","triggerScenarios":"Passing a non-Ogg file (raw Opus, WAV, MP3) to oggreader; reading a stream offset from byte 0 (e.g. after seeking); a truncated/corrupt file whose first bytes were overwritten.","commonSituations":"Wrong file extension vs actual content, concatenated or partially downloaded files, reading from the middle of a container, test fixtures with intentionally corrupted headers.","solutions":["Verify the input actually starts with the 'OggS' magic bytes before parsing","Open the correct file / seek to offset 0 of the Ogg stream","Check the caller that produced the byte slice for off-by-one or header-stripping bugs","Use a tool (ogginfo) to confirm the file integrity; regenerate if corrupt"],"exampleFix":"// before\nf, _ := os.Open(\"audio.opus\") // actually raw opus, no ogg container\n_, _, err := oggreader.NewWith(f) // errBadIDPageSignature\n// after\n// mux raw opus into an ogg container first, then:\nf, _ := os.Open(\"audio.ogg\")\n_, _, err := oggreader.NewWith(f)","handlingStrategy":"validation","validationCode":"sig := make([]byte, 4)\nif _, err := io.ReadFull(f, sig); err != nil || string(sig) != \"OggS\" {\n    return errors.New(\"input is not an Ogg stream\")\n}\n// rewind, then: oggreader.NewWith(io.MultiReader(bytes.NewReader(sig), f))","typeGuard":"func isOggStream(b []byte) bool { return len(b) >= 4 && string(b[:4]) == \"OggS\" }","tryCatchPattern":"_, _, err := oggreader.NewWith(f)\nif err != nil {\n    if errors.Is(err, oggreader.ErrBadIDPageSignature) { // sentinel as exported by the package\n        return fmt.Errorf(\"not a valid Ogg file: %w\", err)\n    }\n    return err\n}","preventionTips":["Confirm the 'OggS' magic before handing a file to the reader","Seek to byte 0 of the Ogg stream before parsing","Do not strip container headers before demuxing","Validate downloaded/moved files for integrity (checksum) before parsing"],"tags":["go","media","ogg","corrupt-file"],"backgroundTag":"bad-file-signature","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"}