{"record":{"id":"31ba8be7c49e5758","repo":"DrKLO/Telegram","slug":"invalid-payload-length-n","errorCode":null,"errorMessage":"Invalid payload length\\n","messagePattern":"Invalid payload length\\\\n","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"TMessagesProj/jni/opus/src/repacketizer_demo.c","lineNumber":131,"sourceCode":"   rp = opus_repacketizer_create();\n   while (!eof)\n   {\n      int err;\n      int nb_packets=merge;\n      opus_repacketizer_init(rp);\n      for (i=0;i<nb_packets;i++)\n      {\n         unsigned char ch[4];\n         err = fread(ch, 1, 4, fin);\n         len[i] = char_to_int(ch);\n         /*fprintf(stderr, \"in len = %d\\n\", len[i]);*/\n         if (len[i]>1500 || len[i]<0)\n         {\n             if (feof(fin))\n             {\n                eof = 1;\n             } else {\n                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));","sourceCodeStart":113,"sourceCodeEnd":149,"githubUrl":"https://github.com/DrKLO/Telegram/blob/45ab8f4308496e1f01026a97fcdb0d58a5274474/TMessagesProj/jni/opus/src/repacketizer_demo.c#L113-L149","documentation":"The tool reads a 4-byte big-endian length prefix via char_to_int() for each packet. If the decoded length exceeds 1500 bytes or is negative, and the stream is not at EOF, the input is considered corrupt. This guard exists because the packets buffer is sized [1500] per packet (line 62); a length beyond 1500 would overflow that buffer. A clean EOF is handled separately (setting eof=1 and breaking the loop).","triggerScenarios":"The input file is not in the expected length-prefixed format (e.g., raw Opus bitstream without the 4-byte length + 4-byte range headers); the file is truncated mid-header causing char_to_int to decode garbage; the file was written by a tool with a different endianness or format; bit corruption in the file.","commonSituations":"Feeding an .opus or .ogg container file instead of the raw length-prefixed packet dump; using output from a different codec or an older format version; file corruption during transfer.","solutions":["Ensure the input file was produced by opus_demo or a compatible tool that writes 4-byte length + 4-byte range-state + payload per packet.","Validate the file format: the first 4 bytes should decode to a plausible packet length (1-1500).","Regenerate the input file from the original encoder.","If the file is intentionally in a different format, write a converter that emits the expected framing."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// Validate input file framing before processing\nint validate_packet_framing(FILE *fin) {\n    unsigned char ch[4];\n    long pos = ftell(fin);\n    if (fread(ch, 1, 4, fin) != 4) { fseek(fin, pos, SEEK_SET); return -1; }\n    int len = (ch[0]<<24)|(ch[1]<<16)|(ch[2]<<8)|ch[3];\n    fseek(fin, pos, SEEK_SET);\n    if (len < 0 || len > 1500) return -1;\n    return 0;\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Only feed files produced by opus_demo or tools using the same 4-byte-length + 4-byte-range + payload framing.","Do not pass .opus, .ogg, or .wav container files directly.","Write a format validator that checks the first packet length is in [1, 1500]."],"tags":["opus","cli","input-validation","data-integrity","repacketizer","file-format"],"backgroundTag":null,"analyzedSha":"45ab8f4308496e1f01026a97fcdb0d58a5274474","analyzedAt":"2026-08-14T05:19:30.815Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}