DrKLO/Telegram · error
Invalid path to YUV file!
Error message
Invalid path to YUV file!
What it means
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.
Source
Thrown at TMessagesProj/jni/mozjpeg/jpegyuv.c:160
for (y = 0; y < 8 && chroma_scanline + y < chroma_height; y++) {
for (x = 0; x < chroma_width; x++) {
yuv_buffer[luma_width*luma_height +
chroma_width*(chroma_scanline + y) + x] = cbrow_pointer[y][x];
yuv_buffer[luma_width*luma_height + chroma_width*chroma_height +
chroma_width*(chroma_scanline + y) + x] = crrow_pointer[y][x];
}
}
}
jpeg_finish_decompress(&cinfo);
jpeg_destroy_decompress(&cinfo);
fclose(jpg_fd);
free(jpg_buffer);
yuv_fd = fopen(yuv_path, "wb");
if (!yuv_fd) {
fprintf(stderr, "Invalid path to YUV file!");
free(yuv_buffer);
return 1;
}
if (fwrite(yuv_buffer, yuv_size, 1, yuv_fd) != 1) {
fprintf(stderr, "Error writing yuv file\n");
}
fclose(yuv_fd);
free(yuv_buffer);
return 0;
}
View on GitHub (pinned to 45ab8f4308)
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
Example fix
// before (JNI) nativeConvertJpegToYuv(jpgPath, "/sdcard/yuv/output.yuv"); // after File outDir = context.getFilesDir(); new File(outDir, "yuv").mkdirs(); String yuvPath = new File(outDir, "yuv/output.yuv").getAbsolutePath(); nativeConvertJpegToYuv(jpgPath, yuvPath);
Defensive patterns
Strategy: validation
Validate before calling
// Validate output path and create parent directory before calling jpegyuv
int validate_yuv_output(const char *path) {
if (path == NULL || path[0] == '\0') return -1;
// Extract and check/create parent directory
char dir[4096];
strncpy(dir, path, sizeof(dir)-1); dir[sizeof(dir)-1] = '\0';
char *slash = strrchr(dir, '/');
if (slash) {
*slash = '\0';
if (access(dir, W_OK) != 0) {
// try to create it
if (mkdir(dir, 0700) != 0 && errno != EEXIST) return -1;
}
}
return 0;
} Prevention
- Create the output directory before invoking jpegyuv
- Verify write permission on the output directory
- Use the app's internal storage for YUV output files
When it happens
Trigger: Output directory doesn't exist. No write permission on the output directory. The output path is a directory itself. Disk full preventing file creation.
Common situations: 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.
Related errors
- %s: can't open %s for writing
- Invalid path to JPEG file!
- Error writing yuv file
- %s: can't open %s for reading
- %s: can't open %s
AI-assisted analysis of DrKLO/Telegram@45ab8f4308 (2026-08-14).
Data as JSON: /api/errors/00c80f01af2b4313.
Report an issue: GitHub.