{"record":{"id":"7e9bd8cfe7a4eddc","repo":"DrKLO/Telegram","slug":"opus-repacketizer-cat-failed-s-n","errorCode":null,"errorMessage":"opus_repacketizer_cat() failed: %s\\n","messagePattern":"opus_repacketizer_cat\\(\\) failed: (.+?)\\\\n","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"TMessagesProj/jni/opus/src/repacketizer_demo.c","lineNumber":149,"sourceCode":"                fprintf(stderr, \"Invalid payload length\\n\");\n                fclose(fin);\n                fclose(fout);\n                return EXIT_FAILURE;\n             }\n             break;\n         }\n         err = fread(ch, 1, 4, fin);\n         rng[i] = char_to_int(ch);\n         err = fread(packets[i], 1, len[i], fin);\n         if (feof(fin))\n         {\n            eof = 1;\n            break;\n         }\n         err = opus_repacketizer_cat(rp, packets[i], len[i]);\n         if (err!=OPUS_OK)\n         {\n            fprintf(stderr, \"opus_repacketizer_cat() failed: %s\\n\", opus_strerror(err));\n            break;\n         }\n      }\n      nb_packets = i;\n\n      if (eof)\n         break;\n\n      if (!split)\n      {\n         err = opus_repacketizer_out(rp, output_packet, MAX_PACKETOUT);\n         if (err>0) {\n            unsigned char int_field[4];\n            int_to_char(err, int_field);\n            if(fwrite(int_field, 1, 4, fout)!=4){\n               fprintf(stderr, \"Error writing.\\n\");\n               return EXIT_FAILURE;\n            }","sourceCodeStart":131,"sourceCodeEnd":167,"githubUrl":"https://github.com/DrKLO/Telegram/blob/45ab8f4308496e1f01026a97fcdb0d58a5274474/TMessagesProj/jni/opus/src/repacketizer_demo.c#L131-L167","documentation":"opus_repacketizer_cat() returned a status other than OPUS_OK when adding a packet to the repacketizer context. This library function validates the packet before merging it: it checks that the packet is a valid Opus packet and that its configuration (sample rate, frame size, mode, bandwidth) is compatible with packets already in the buffer. The specific error code is translated to a human-readable string by opus_strerror(). After the error, the loop breaks but the tool does not exit immediately — it proceeds to output whatever packets were successfully buffered.","triggerScenarios":"Merging packets from different encoder instances with different configurations; merging packets with different frame sizes (e.g., 20ms and 40ms); merging a CELT-mode packet with a SILK-mode packet; passing a malformed or truncated packet payload; exceeding the maximum merged packet size. The most common error code is OPUS_INVALID_PACKET.","commonSituations":"Concatenating packets from different audio streams; a bug in the packet-generation step producing malformed packets; mixing narrowband and wideband packets; version mismatch between encoder and the repacketizer API.","solutions":["Ensure all packets being merged come from the same encoder session with identical configuration (same sample rate, channels, application, frame size).","Log the opus_strerror output to identify the specific failure (OPUS_INVALID_PACKET vs OPUS_BAD_ARG).","Validate each packet with opus_packet_parse before feeding it to the repacketizer.","Reduce the merge count to isolate which packet triggers the error."],"exampleFix":"// before\nerr = opus_repacketizer_cat(rp, packets[i], len[i]);\nif (err != OPUS_OK) {\n    fprintf(stderr, \"opus_repacketizer_cat() failed: %s\\n\", opus_strerror(err));\n    break;\n}\n// after: validate packet compatibility before cat\nint toc = packets[i][0];\nint frame_size_check = opus_packet_get_nb_samples(packets[i], len[i], 48000);\nif (frame_size_check <= 0) {\n    fprintf(stderr, \"Skipping invalid packet at index %d\\n\", i);\n    continue;\n}\nerr = opus_repacketizer_cat(rp, packets[i], len[i]);\nif (err != OPUS_OK) {\n    fprintf(stderr, \"opus_repacketizer_cat() failed: %s\\n\", opus_strerror(err));\n    break;\n}","handlingStrategy":"validation","validationCode":"// Validate packet before calling opus_repacketizer_cat\nint safe_cat(OpusRepacketizer *rp, const unsigned char *data, int len) {\n    // Check packet looks valid\n    if (len < 1 || data[0] == 0) return OPUS_INVALID_PACKET;\n    int ret = opus_repacketizer_cat(rp, data, len);\n    if (ret != OPUS_OK) {\n        fprintf(stderr, \"cat failed: %s (len=%d, toc=0x%02x)\\n\",\n                opus_strerror(ret), len, data[0]);\n    }\n    return ret;\n}","typeGuard":null,"tryCatchPattern":"if ((err = opus_repacketizer_cat(rp, data, len)) != OPUS_OK) {\n    fprintf(stderr, \"cat failed: %s\\n\", opus_strerror(err));\n    // optionally: skip this packet and continue, or abort\n    break;\n}","preventionTips":["Ensure all packets originate from the same encoder session with identical configuration.","Validate packet TOC byte and frame count with opus_packet_get_nb_frames before merging.","Log the TOC byte and length of each packet to diagnose configuration mismatches.","Use opus_repacketizer_init before each batch to start with a clean state."],"tags":["opus","library-api","repacketizer","packet-validation","configuration-mismatch"],"backgroundTag":null,"analyzedSha":"45ab8f4308496e1f01026a97fcdb0d58a5274474","analyzedAt":"2026-08-14T05:19:30.815Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}