{"record":{"id":"00c80f01af2b4313","repo":"DrKLO/Telegram","slug":"invalid-path-to-yuv-file","errorCode":null,"errorMessage":"Invalid path to YUV file!","messagePattern":"Invalid path to YUV file!","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"TMessagesProj/jni/mozjpeg/jpegyuv.c","lineNumber":160,"sourceCode":"    for (y = 0; y < 8 && chroma_scanline + y < chroma_height; y++) {\n      for (x = 0; x < chroma_width; x++) {\n        yuv_buffer[luma_width*luma_height +\n         chroma_width*(chroma_scanline + y) + x] = cbrow_pointer[y][x];\n        yuv_buffer[luma_width*luma_height + chroma_width*chroma_height +\n         chroma_width*(chroma_scanline + y) + x] = crrow_pointer[y][x];\n      }\n    }\n  }\n\n  jpeg_finish_decompress(&cinfo);\n  jpeg_destroy_decompress(&cinfo);\n\n  fclose(jpg_fd);\n  free(jpg_buffer);\n\n  yuv_fd = fopen(yuv_path, \"wb\");\n  if (!yuv_fd) {\n    fprintf(stderr, \"Invalid path to YUV file!\");\n    free(yuv_buffer);\n    return 1;\n  }\n  if (fwrite(yuv_buffer, yuv_size, 1, yuv_fd) != 1) {\n    fprintf(stderr, \"Error writing yuv file\\n\");\n  }\n\n  fclose(yuv_fd);\n  free(yuv_buffer);\n\n  return 0;\n}\n","sourceCodeStart":142,"sourceCodeEnd":173,"githubUrl":"https://github.com/DrKLO/Telegram/blob/45ab8f4308496e1f01026a97fcdb0d58a5274474/TMessagesProj/jni/mozjpeg/jpegyuv.c#L142-L173","documentation":"jpegyuv opens the YUV output file with fopen(yuv_path, \"wb\") at jpegyuv.c:158. If fopen returns NULL, the output path's parent directory doesn't exist, the process lacks write permission, or the path is invalid. The program frees the YUV buffer and returns 1. Notably, the error message lacks a trailing newline (unlike other messages in the file), which can cause the next shell prompt to appear on the same line.","triggerScenarios":"Output directory doesn't exist. No write permission on the output directory. The output path is a directory itself. Disk full preventing file creation.","commonSituations":"JNI caller passes an output path in a directory the native process can't write to. On Android, writing to external storage without proper permissions. Output path points to a read-only filesystem mount.","solutions":["Create the parent directory before invoking: `mkdir -p $(dirname yuv_path)`","Verify write permission on the output directory","Use the app's internal storage for output","Add the missing newline to the error message in jpegyuv.c for cleaner output"],"exampleFix":"// before (JNI)\nnativeConvertJpegToYuv(jpgPath, \"/sdcard/yuv/output.yuv\");\n\n// after\nFile outDir = context.getFilesDir();\nnew File(outDir, \"yuv\").mkdirs();\nString yuvPath = new File(outDir, \"yuv/output.yuv\").getAbsolutePath();\nnativeConvertJpegToYuv(jpgPath, yuvPath);","handlingStrategy":"validation","validationCode":"// Validate output path and create parent directory before calling jpegyuv\nint validate_yuv_output(const char *path) {\n    if (path == NULL || path[0] == '\\0') return -1;\n    // Extract and check/create parent directory\n    char dir[4096];\n    strncpy(dir, path, sizeof(dir)-1); dir[sizeof(dir)-1] = '\\0';\n    char *slash = strrchr(dir, '/');\n    if (slash) {\n        *slash = '\\0';\n        if (access(dir, W_OK) != 0) {\n            // try to create it\n            if (mkdir(dir, 0700) != 0 && errno != EEXIST) return -1;\n        }\n    }\n    return 0;\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Create the output directory before invoking jpegyuv","Verify write permission on the output directory","Use the app's internal storage for YUV output files"],"tags":["jpeg","jpegyuv","file-io","write-permission","output"],"backgroundTag":null,"analyzedSha":"45ab8f4308496e1f01026a97fcdb0d58a5274474","analyzedAt":"2026-08-14T05:19:30.815Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}