{"record":{"id":"d3681e0bb6041bda","repo":"DrKLO/Telegram","slug":"invalid-channel-count-channelcount","errorCode":null,"errorMessage":"Invalid channel count: {channelCount}","messagePattern":"Invalid channel count: (.+?)","errorType":"exception","errorClass":"OpusDecoderException","httpStatus":null,"severity":"error","filePath":"TMessagesProj/src/main/java/com/google/android/exoplayer2/ext/opus/OpusDecoder.java","lineNumber":109,"sourceCode":"    int initializationDataSize = initializationData.size();\n    if (initializationDataSize != 1 && initializationDataSize != 3) {\n      throw new OpusDecoderException(\"Invalid initialization data size\");\n    }\n    if (initializationDataSize == 3\n        && (initializationData.get(1).length != 8 || initializationData.get(2).length != 8)) {\n      throw new OpusDecoderException(\"Invalid pre-skip or seek pre-roll\");\n    }\n    preSkipSamples = getPreSkipSamples(initializationData);\n    seekPreRollSamples = getSeekPreRollSamples(initializationData);\n    skipSamples = preSkipSamples;\n\n    byte[] headerBytes = initializationData.get(0);\n    if (headerBytes.length < 19) {\n      throw new OpusDecoderException(\"Invalid header length\");\n    }\n    channelCount = getChannelCount(headerBytes);\n    if (channelCount > 8) {\n      throw new OpusDecoderException(\"Invalid channel count: \" + channelCount);\n    }\n    int gain = readSignedLittleEndian16(headerBytes, 16);\n\n    byte[] streamMap = new byte[8];\n    int numStreams;\n    int numCoupled;\n    if (headerBytes[18] == 0) { // Channel mapping\n      // If there is no channel mapping, use the defaults.\n      if (channelCount > 2) { // Maximum channel count with default layout.\n        throw new OpusDecoderException(\"Invalid header, missing stream map\");\n      }\n      numStreams = 1;\n      numCoupled = (channelCount == 2) ? 1 : 0;\n      streamMap[0] = 0;\n      streamMap[1] = 1;\n    } else {\n      if (headerBytes.length < 21 + channelCount) {\n        throw new OpusDecoderException(\"Invalid header length\");","sourceCodeStart":91,"sourceCodeEnd":127,"githubUrl":"https://github.com/DrKLO/Telegram/blob/45ab8f4308496e1f01026a97fcdb0d58a5274474/TMessagesProj/src/main/java/com/google/android/exoplayer2/ext/opus/OpusDecoder.java#L91-L127","documentation":"Channel count is read from headerBytes[9] (& 0xFF). This decoder caps it at 8 because the per-stream mapping array (streamMap) is allocated as new byte[8] (OpusDecoder.java:113). Opus itself allows up to 255 channels via mapping family 1, but this extension's multistream wiring only supports up to 8.","triggerScenarios":"An Opus stream whose identification header reports more than 8 channels, or a corrupt header byte 9 producing a large value.","commonSituations":"Rare legitimate >8-channel Opus content routed to this decoder; corrupted headers where byte 9 is garbage; mis-detected codec feeding non-Opus bytes.","solutions":["Use Opus content with 8 or fewer channels (up to 7.1).","If you need more channels, use a decoder whose native multistream wiring supports them.","If the count looks like garbage, suspect a corrupt/wrong file rather than a real multichannel stream."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"int ch = format.initializationData.get(0)[9] & 0xFF;\nif (ch < 1 || ch > 8) {\n  throw new IllegalArgumentException(\"Opus channel count out of range (1..8): \" + ch);\n}\nnew OpusDecoder(NUM_BUFFERS, NUM_BUFFERS, initSize, format.initializationData, cryptoConfig, outputFloat);","typeGuard":null,"tryCatchPattern":"try {\n  new OpusDecoder(..., format.initializationData, cryptoConfig, outputFloat);\n} catch (OpusDecoderException e) {\n  if (e.getMessage().startsWith(\"Invalid channel count\")) {\n    // route to a decoder supporting >8 channels, or mark unsupported\n  } else { throw e; }\n}","preventionTips":["Restrict Opus content to 8 or fewer channels for this decoder.","Sanity-check the channel byte (header[9]) before constructing the decoder."],"tags":["opus","decoder","format-validation","exoplayer","audio"],"backgroundTag":null,"analyzedSha":"45ab8f4308496e1f01026a97fcdb0d58a5274474","analyzedAt":"2026-08-14T05:19:30.815Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}