{"record":{"id":"7408b2ad55ad41e4","repo":"DrKLO/Telegram","slug":"s-can-t-write-to-s","errorCode":null,"errorMessage":"%s: can't write to %s\n","messagePattern":"(.+?): can't write to (.+?)\n","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"TMessagesProj/jni/mozjpeg/jpegtran.c","lineNumber":670,"sourceCode":"  jpeg_finish_compress(&dstinfo);\n\n#if JPEG_LIB_VERSION >= 80 || defined(MEM_SRCDST_SUPPORTED)\n  if (jpeg_c_int_param_supported(&dstinfo, JINT_COMPRESS_PROFILE) &&\n      jpeg_c_get_int_param(&dstinfo, JINT_COMPRESS_PROFILE)\n        == JCP_MAX_COMPRESSION) {\n    size_t nbytes;\n    \n    unsigned char *buffer = outbuffer;\n    unsigned long size = outsize;\n    if (prefer_smallest && insize < size) {\n      size = insize;\n      buffer = inbuffer;\n    }\n\n    nbytes = JFWRITE(fp, buffer, size);\n    if (nbytes < size && ferror(fp)) {\n      if (file_index < argc)\n        fprintf(stderr, \"%s: can't write to %s\\n\", progname,\n                argv[file_index]);\n      else\n        fprintf(stderr, \"%s: can't write to stdout\\n\", progname);\n    }\n  }\n#endif\n    \n  jpeg_destroy_compress(&dstinfo);\n  (void)jpeg_finish_decompress(&srcinfo);\n  jpeg_destroy_decompress(&srcinfo);\n\n  /* Close output file, if we opened it */\n  if (fp != stdout)\n    fclose(fp);\n\n#ifdef PROGRESS_REPORT\n  end_progress_monitor((j_common_ptr)&dstinfo);\n#endif","sourceCodeStart":652,"sourceCodeEnd":688,"githubUrl":"https://github.com/DrKLO/Telegram/blob/45ab8f4308496e1f01026a97fcdb0d58a5274474/TMessagesProj/jni/mozjpeg/jpegtran.c#L652-L688","documentation":"In JCP_MAX_COMPRESSION mode, jpegtran writes the output buffer via JFWRITE(fp, buffer, size) at jpegtran.c:667. If fewer than `size` bytes are written and ferror(fp) is true, a write error occurred on the output file. Unlike the open failure, this happens after successful compression. The error message names the input file path (argv[file_index]) rather than the output path.","triggerScenarios":"Disk fills up during the write. Quota exceeded mid-write. The output file is on a filesystem that becomes read-only (e.g. ext4 remounted ro on error). A broken pipe to a downstream process that closed early.","commonSituations":"Large JPEG output written to nearly-full storage. Android external storage that gets unmounted mid-write. Writing to a FUSE filesystem with a quota. The output is piped to a viewer that exits before jpegtran finishes.","solutions":["Check available disk space before processing: ensure at least 2-3x the input file size is free","Write output to internal storage first, then move to the final destination","Handle the partial output file: delete it so stale data isn't used","Avoid piping output to processes that may exit early"],"exampleFix":"// before\njpegtran input.jpg -outfile /sdcard/nearly_full/out.jpg\n\n// after\n// check free space first\nlong free = get_available_bytes(\"/sdcard/\");\nif (free < input_size * 3) {\n    fprintf(stderr, \"insufficient disk space\\n\");\n    return -1;\n}\njpegtran input.jpg -outfile /sdcard/nearly_full/out.jpg","handlingStrategy":"validation","validationCode":"// Check available disk space before processing\n#include <sys/statvfs.h>\nint check_disk_space(const char *output_dir, size_t min_bytes) {\n    struct statvfs vfs;\n    if (statvfs(output_dir, &vfs) != 0) return -1;\n    unsigned long long avail = (unsigned long long)vfs.f_bavail * vfs.f_bsize;\n    if (avail < min_bytes) {\n        fprintf(stderr, \"Insufficient disk space: have %llu, need %zu\\n\",\n                avail, min_bytes);\n        return -1;\n    }\n    return 0;\n}\n// Call: check_disk_space(dirname(output_path), input_size * 3);","typeGuard":null,"tryCatchPattern":"// After jpegtran, verify output file was fully written\nstruct stat st;\nif (stat(output_path, &st) != 0 || st.st_size == 0) {\n    unlink(output_path); // remove partial output\n    return -1;\n}","preventionTips":["Ensure at least 3x the input file size is available on the output device","Write to internal storage first, then move to the final destination","Delete partial output files after a write failure"],"tags":["jpeg","jpegtran","file-io","write-error","disk-full","max-compression"],"backgroundTag":null,"analyzedSha":"45ab8f4308496e1f01026a97fcdb0d58a5274474","analyzedAt":"2026-08-14T05:19:30.815Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}