{"record":{"id":"b5ffbd0c0630a85d","repo":"DrKLO/Telegram","slug":"unexpected-input-format-n","errorCode":null,"errorMessage":"Unexpected input format!\\n","messagePattern":"Unexpected input format!\\\\n","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"TMessagesProj/jni/mozjpeg/yuvjpeg.c","lineNumber":164,"sourceCode":"  /* Will check these for validity when opening via 'fopen'. */\n  yuv_path = argv[3];\n  jpg_path = argv[4];\n\n  yuv_fd = fopen(yuv_path, \"r\");\n  if (!yuv_fd) {\n    fprintf(stderr, \"Invalid path to YUV file!\\n\");\n    return 1;\n  }\n\n  fseek(yuv_fd, 0, SEEK_END);\n  yuv_size = ftell(yuv_fd);\n  fseek(yuv_fd, 0, SEEK_SET);\n\n  /* Check that the file size matches 4:2:0 yuv. */\n  if (yuv_size !=\n   (size_t)luma_width*luma_height + 2*chroma_width*chroma_height) {\n    fclose(yuv_fd);\n    fprintf(stderr, \"Unexpected input format!\\n\");\n    return 1;\n  }\n\n  yuv_buffer = malloc(yuv_size);\n  if (!yuv_buffer) {\n    fclose(yuv_fd);\n    fprintf(stderr, \"Memory allocation failure!\\n\");\n    return 1;\n  }\n\n  if (fread(yuv_buffer, yuv_size, 1, yuv_fd) != 1) {\n    fprintf(stderr, \"Error reading yuv file\\n\");\n  };\n\n  fclose(yuv_fd);\n\n  frame_width = (luma_width + (16 - 1)) & ~(16 - 1);\n  frame_height = (luma_height + (16 - 1)) & ~(16 - 1);","sourceCodeStart":146,"sourceCodeEnd":182,"githubUrl":"https://github.com/DrKLO/Telegram/blob/45ab8f4308496e1f01026a97fcdb0d58a5274474/TMessagesProj/jni/mozjpeg/yuvjpeg.c#L146-L182","documentation":"yuvjpeg computes the expected 4:2:0 byte size as luma_width*luma_height + 2*chroma_width*chroma_height (chroma dims = ceil(luma/2)) and compares it to the YUV file size from ftell. If they differ it closes the file, prints `Unexpected input format!`, and returns 1. This catches dimension/file mismatches and non-4:2:0 layouts before decoding.","triggerScenarios":"The declared WxH does not match the actual YUV frame, the file is truncated/padded, the layout is not 4:2:0 (e.g. 4:4:4 or 4:2:2), or there are extra header/padding bytes.","commonSituations":"Wrong size argument vs real capture resolution, feeding a Y4M or NV12 container instead of raw I420, endianness/stride padding, or a partially downloaded file.","solutions":["Match the WxH argument exactly to the source frame's luma dimensions.","Ensure the input is raw planar 4:2:0 (I420) with no container/header/stride padding.","Strip any Y4M headers or convert NV12/other layouts to I420 first.","Verify file size equals W*H + 2*((W+1)/2)*((H+1)/2) before invoking."],"exampleFix":"// before\nyuvjpeg 90 1280x720 frame.yuv out.jpg   # frame is actually 1920x1080\n// after\nyuvjpeg 90 1920x1080 frame.yuv out.jpg","handlingStrategy":"validation","validationCode":"#include <sys/stat.h>\n/* expected 4:2:0 (I420) byte size for the declared dimensions */\nlong cw = (luma_width + 1) / 2, ch = (luma_height + 1) / 2;\nsize_t expected = (size_t)luma_width * luma_height + 2 * cw * ch;\nstruct stat st;\nif (stat(yuv_path, &st) != 0 || (size_t)st.st_size != expected) {\n    /* dimensions do not match file; reject before invoking yuvjpeg */\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Match WxH exactly to the source frame's luma dimensions.","Feed only raw planar I420 with no header/stride padding.","Pre-check file size == W*H + 2*ceil(W/2)*ceil(H/2).","Convert NV12/Y4M/4:2:2 to I420 before passing to yuvjpeg."],"tags":["cli","jpeg","mozjpeg","yuvjpeg","input-validation","format","yuv","video"],"backgroundTag":null,"analyzedSha":"45ab8f4308496e1f01026a97fcdb0d58a5274474","analyzedAt":"2026-08-14T05:19:30.815Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}