DrKLO/Telegram · error · FlacDecoderException

Failed to decode StreamInfo

Error message

Failed to decode StreamInfo

What it means

FlacDecoder wraps a ParserException from decoderJni.decodeStreamMetadata() as FlacDecoderException('Failed to decode StreamInfo'). The native FLAC parser could not read a valid STREAMINFO metadata block from the provided header data, so stream parameters (sample rate, channels, frame size) are unknown and decoding cannot continue.

Source

Thrown at TMessagesProj/src/main/java/com/google/android/exoplayer2/ext/flac/FlacDecoder.java:67

   *     which is the flac file header.
   * @throws FlacDecoderException Thrown if an exception occurs when initializing the decoder.
   */
  public FlacDecoder(
      int numInputBuffers,
      int numOutputBuffers,
      int maxInputBufferSize,
      List<byte[]> initializationData)
      throws FlacDecoderException {
    super(new DecoderInputBuffer[numInputBuffers], new SimpleDecoderOutputBuffer[numOutputBuffers]);
    if (initializationData.size() != 1) {
      throw new FlacDecoderException("Initialization data must be of length 1");
    }
    decoderJni = new FlacDecoderJni();
    decoderJni.setData(ByteBuffer.wrap(initializationData.get(0)));
    try {
      streamMetadata = decoderJni.decodeStreamMetadata();
    } catch (ParserException e) {
      throw new FlacDecoderException("Failed to decode StreamInfo", e);
    } catch (IOException e) {
      // Never happens.
      throw new IllegalStateException(e);
    }

    int initialInputBufferSize =
        maxInputBufferSize != Format.NO_VALUE ? maxInputBufferSize : streamMetadata.maxFrameSize;
    setInitialInputBufferSize(initialInputBufferSize);
  }

  @Override
  public String getName() {
    return "libflac";
  }

  @Override
  protected DecoderInputBuffer createInputBuffer() {
    return new DecoderInputBuffer(DecoderInputBuffer.BUFFER_REPLACEMENT_MODE_NORMAL);

View on GitHub (pinned to 45ab8f4308)

Solutions

  1. Re-extract or re-derive the FLAC header so it contains a valid STREAMINFO block before instantiating the decoder.
  2. Verify the source media is genuinely FLAC (magic bytes 'fLaC') and not mislabeled.
  3. Fall back to the platform FLAC decoder or skip the track.

Example fix

// before
init = Collections.singletonList(truncatedHeader);

// after
List<byte[]> init = extractor.getInitializationData(); // guaranteed valid STREAMINFO
new FlacDecoder(nIn, nOut, maxIn, init);
Defensive patterns

Strategy: try-catch

Validate before calling

// sanity-check the header before constructing
byte[] header = initializationData.get(0);
boolean looksFlac = header != null && header.length >= 4
    && header[0]=='f' && header[1]=='L' && header[2]=='a' && header[3]=='C';
if (!looksFlac) { /* re-extract header or skip */ }

Try / catch

try { new FlacDecoder(nIn, nOut, maxIn, init); }
catch (FlacDecoderException e) { /* fall back to platform FLAC or skip track */ }

Prevention

When it happens

Trigger: The single initializationData entry is present but does not contain a parseable FLAC STREAMINFO block; the header is truncated, corrupt, or not actually FLAC.

Common situations: Corrupt/truncated FLAC header in the initializationData; misidentified media (non-FLAC bytes passed as FLAC); a remuxed stream whose header was altered; native library version mismatch in metadata parsing.

Understand the failure class

Related errors


AI-assisted analysis of DrKLO/Telegram@45ab8f4308 (2026-08-14). Data as JSON: /api/errors/1be7aa5b310b02f7. Report an issue: GitHub.