DrKLO/Telegram · error · FlacDecoderException

Initialization data must be of length 1

Error message

Initialization data must be of length 1

What it means

FlacDecoder's constructor throws FlacDecoderException('Initialization data must be of length 1') unless the initializationData list contains exactly one entry — that entry being the FLAC file/stream header used to bootstrap the native decoder. Any other length means the decoder cannot locate the stream header.

Solutions

  1. Ensure the FLAC extractor supplies exactly one initialization entry containing the full FLAC stream header.
  2. Validate initializationData.size()==1 before instantiating FlacDecoder.
  3. Use the platform FLAC decoder or re-extract the stream if the header cannot be supplied as a single entry.

Example fix

// before
new FlacDecoder(nIn, nOut, maxIn, /* size 0 or 2 */ init);

// after
checkArgument(init.size() == 1, "FLAC init must be a single header entry");
new FlacDecoder(nIn, nOut, maxIn, init);
Defensive patterns

Strategy: validation

Validate before calling

// enforce the single-entry invariant before constructing
checkArgument(initializationData.size() == 1,
    "FLAC init must contain exactly one header entry");
new FlacDecoder(nIn, nOut, maxIn, initializationData);

Try / catch

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

Prevention

When it happens

Trigger: Constructing FlacDecoder with an initializationData list whose size() != 1 (zero entries, or more than one entry, e.g. because multiple headers were collected).

Common situations: A FLAC extractor or source providing zero or multiple initialization entries; a malformed FLAC stream whose header was split or absent; feeding non-FLAC initialization data.

Related errors


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

Appendix: source

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

   * Creates a Flac decoder.
   *
   * @param numInputBuffers The number of input buffers.
   * @param numOutputBuffers The number of output buffers.
   * @param maxInputBufferSize The maximum required input buffer size if known, or {@link
   *     Format#NO_VALUE} otherwise.
   * @param initializationData Codec-specific initialization data. It should contain only one entry
   *     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

View on GitHub (pinned to 45ab8f4308)