{"record":{"id":"89b16cbcfb5451a4","repo":"DrKLO/Telegram","slug":"invalid-path-to-jpeg-file","errorCode":null,"errorMessage":"Invalid path to JPEG file!\n","messagePattern":"Invalid path to JPEG file!\n","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"TMessagesProj/jni/mozjpeg/jpegyuv.c","lineNumber":79,"sourceCode":"  FILE *yuv_fd;\n\n  if (argc != 3) {\n    fprintf(stderr, \"Required arguments:\\n\");\n    fprintf(stderr, \"1. Path to JPG input file\\n\");\n    fprintf(stderr, \"2. Path to YUV output file\\n\");\n    return 1;\n  }\n\n  /* Will check these for validity when opening via 'fopen'. */\n  jpg_path = argv[1];\n  yuv_path = argv[2];\n\n  cinfo.err = jpeg_std_error(&jerr);\n  jpeg_create_decompress(&cinfo);\n\n  jpg_fd = fopen(jpg_path, \"rb\");\n  if (!jpg_fd) {\n    fprintf(stderr, \"Invalid path to JPEG file!\\n\");\n    return 1;\n  }\n\n  jpeg_stdio_src(&cinfo, jpg_fd);\n\n  jpeg_read_header(&cinfo, TRUE);\n\n  cinfo.raw_data_out = TRUE;\n  cinfo.do_fancy_upsampling = FALSE;\n\n  jpeg_start_decompress(&cinfo);\n\n  luma_width = cinfo.output_width;\n  luma_height = cinfo.output_height;\n\n  chroma_width = (luma_width + 1) >> 1;\n  chroma_height = (luma_height + 1) >> 1;\n","sourceCodeStart":61,"sourceCodeEnd":97,"githubUrl":"https://github.com/DrKLO/Telegram/blob/45ab8f4308496e1f01026a97fcdb0d58a5274474/TMessagesProj/jni/mozjpeg/jpegyuv.c#L61-L97","documentation":"jpegyuv opens the JPEG input with fopen(jpg_path, \"rb\") at jpegyuv.c:77. If fopen returns NULL, the path is invalid: the file doesn't exist, isn't readable, or the path is malformed. The program prints 'Invalid path to JPEG file!' and returns 1 without processing.","triggerScenarios":"The JPEG file path doesn't exist on the filesystem. The path is a directory. The file has restrictive permissions. A relative path that resolves against the wrong working directory in JNI.","commonSituations":"Android JNI caller passes a path from Java that doesn't resolve on the native filesystem (e.g. a content:// URI instead of a real filesystem path). Path has trailing whitespace or a newline. File was deleted between path resolution and fopen.","solutions":["Verify the file exists and is readable: `access(jpg_path, R_OK) == 0` before invoking","Use absolute paths, especially from JNI where cwd may not match expectations","On Android, extract files from content URIs to internal storage first"],"exampleFix":"// before (Java/JNI)\nnativeConvertJpegToYuv(contentUri.getPath(), yuvPath);\n\n// after\nFile tmp = new File(context.getFilesDir(), \"input.jpg\");\ncopyUriToFile(contentUri, tmp);\nnativeConvertJpegToYuv(tmp.getAbsolutePath(), yuvPath);","handlingStrategy":"validation","validationCode":"// Validate JPEG input file before calling jpegyuv\nint validate_jpeg_for_yuv(const char *path) {\n    if (path == NULL || path[0] == '\\0') return -1;\n    if (access(path, R_OK) != 0) return -1;\n    struct stat st;\n    if (stat(path, &st) != 0) return -1;\n    if (!S_ISREG(st.st_mode)) return -1;\n    if (st.st_size < 3) return -1; // too small for JPEG (FFD8 minimum)\n    return 0;\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Call access(path, R_OK) before invoking jpegyuv","Use absolute paths from JNI; relative paths may resolve against the wrong cwd","On Android, copy files from content URIs to internal storage before processing"],"tags":["jpeg","jpegyuv","file-io","permissions","input"],"backgroundTag":null,"analyzedSha":"45ab8f4308496e1f01026a97fcdb0d58a5274474","analyzedAt":"2026-08-14T05:19:30.815Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}