{"record":{"id":"1c4555be4ddcaa61","repo":"DrKLO/Telegram","slug":"cannot-read-frame-at-position-lastdecodeposition","errorCode":null,"errorMessage":"Cannot read frame at position {lastDecodePosition}","messagePattern":"Cannot read frame at position (.+?)","errorType":"exception","errorClass":"IOException","httpStatus":null,"severity":"error","filePath":"TMessagesProj/src/main/java/com/google/android/exoplayer2/ext/flac/FlacExtractor.java","lineNumber":146,"sourceCode":"  public int read(final ExtractorInput input, PositionHolder seekPosition) throws IOException {\n    if (input.getPosition() == 0 && !id3MetadataDisabled && id3Metadata == null) {\n      id3Metadata = FlacMetadataReader.peekId3Metadata(input, /* parseData= */ true);\n    }\n\n    FlacDecoderJni decoderJni = initDecoderJni(input);\n    try {\n      decodeStreamMetadata(input);\n\n      if (binarySearchSeeker != null && binarySearchSeeker.isSeeking()) {\n        return handlePendingSeek(input, seekPosition, outputBuffer, outputFrameHolder, trackOutput);\n      }\n\n      ByteBuffer outputByteBuffer = outputFrameHolder.byteBuffer;\n      long lastDecodePosition = decoderJni.getDecodePosition();\n      try {\n        decoderJni.decodeSampleWithBacktrackPosition(outputByteBuffer, lastDecodePosition);\n      } catch (FlacDecoderJni.FlacFrameDecodeException e) {\n        throw new IOException(\"Cannot read frame at position \" + lastDecodePosition, e);\n      }\n      int outputSize = outputByteBuffer.limit();\n      if (outputSize == 0) {\n        return RESULT_END_OF_INPUT;\n      }\n\n      outputSample(outputBuffer, outputSize, decoderJni.getLastFrameTimestamp(), trackOutput);\n      return decoderJni.isEndOfData() ? RESULT_END_OF_INPUT : RESULT_CONTINUE;\n    } finally {\n      decoderJni.clearData();\n    }\n  }\n\n  @Override\n  public void seek(long position, long timeUs) {\n    if (position == 0) {\n      streamMetadataDecoded = false;\n    }","sourceCodeStart":128,"sourceCodeEnd":164,"githubUrl":"https://github.com/DrKLO/Telegram/blob/45ab8f4308496e1f01026a97fcdb0d58a5274474/TMessagesProj/src/main/java/com/google/android/exoplayer2/ext/flac/FlacExtractor.java#L128-L164","documentation":"FlacExtractor wraps a FlacFrameDecodeException from decoderJni.decodeSampleWithBacktrackPosition(...) as IOException('Cannot read frame at position <lastDecodePosition>'). It records the decoder's last decode position to aid debugging when a frame cannot be read during extraction.","triggerScenarios":"During readSample, decodeSampleWithBacktrackPosition throws FlacFrameDecodeException (see error 77) at lastDecodePosition; the extractor converts it to an IOException that surfaces to the extraction loop.","commonSituations":"Corrupt FLAC input being extracted; a seek landing on an invalid frame; network source providing truncated/garbled FLAC data; mid-stream bitstream errors.","solutions":["Handle IOException at the extractor/player level with a resync or skip-to-next-sample strategy.","Ensure the source provides complete, uncorrupted FLAC bytes (check network/CDN integrity).","Use extractor-based seeking so positions are always frame-aligned."],"exampleFix":"// before\n// extractor.read() propagates IOException up to player -> playback aborts\n\n// after\ntry { extractor.read(...); }\ncatch (IOException e) { /* log position, advance input, continue extraction */ }","handlingStrategy":"try-catch","validationCode":"// n/a: extraction-time I/O error caused by corrupt frames; mitigate by validating source integrity\n// and using extractor-based seeking","typeGuard":null,"tryCatchPattern":"try { extractor.read(input, seekPosition, output); }\ncatch (IOException e) {\n  // log lastDecodePosition, advance input, continue extraction\n}","preventionTips":["Use extractor-driven seeking so positions stay frame-aligned.","Verify the source stream is complete and uncorrupted.","Handle IOException with resync/skip rather than aborting playback."],"tags":["audio","exoplayer","flac","extractor","io","corrupt-data"],"backgroundTag":null,"analyzedSha":"45ab8f4308496e1f01026a97fcdb0d58a5274474","analyzedAt":"2026-08-14T05:19:30.815Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}