{"record":{"id":"5e899547bb64e71e","repo":"DrKLO/Telegram","slug":"s-can-t-write-to-stdout","errorCode":null,"errorMessage":"%s: can't write to stdout\n","messagePattern":"(.+?): can't write to stdout\n","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"TMessagesProj/jni/mozjpeg/jpegtran.c","lineNumber":673,"sourceCode":"  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\n\n  free(inbuffer);\n  free(outbuffer);","sourceCodeStart":655,"sourceCodeEnd":691,"githubUrl":"https://github.com/DrKLO/Telegram/blob/45ab8f4308496e1f01026a97fcdb0d58a5274474/TMessagesProj/jni/mozjpeg/jpegtran.c#L655-L691","documentation":"Same write-error condition as error 151, but fired when output goes to stdout (file_index >= argc). JFWRITE returns fewer than size bytes with ferror(fp) true on stdout. This happens when the downstream consumer of stdout closes the pipe before jpegtran finishes writing.","triggerScenarios":"Piping jpegtran output to `head` which closes the pipe after reading enough. Writing to a redirected file whose disk fills up. A downstream process crashes or is killed. A network socket (via netcat) drops mid-transfer.","commonSituations":"Shell pipeline `jpegtran ... | viewer` where viewer exits early. Redirecting to a file on full storage. Using process substitution that aborts.","solutions":["Write to a file instead of stdout to avoid broken-pipe issues","Use `set -o pipefail` in bash to detect pipeline failures","If piping to a viewer, ensure the viewer reads the entire stream"],"exampleFix":"// before\njpegtran input.jpg | head -c 1000 > preview\n\n// after\njpegtran input.jpg -outfile /tmp/out.jpg\nhead -c 1000 /tmp/out.jpg > preview","handlingStrategy":"validation","validationCode":"// Avoid piping to stdout; write to a file instead\n// In a shell script:\n// before: jpegtran input.jpg | viewer\n// after:\nTMP=$(mktemp)\njpegtran input.jpg -outfile \"$TMP\"\nif [ $? -eq 0 ]; then\n    cat \"$TMP\" | viewer\nfi\nrm -f \"$TMP\"","typeGuard":null,"tryCatchPattern":"// If you must pipe, use pipefail and check\nset -o pipefail\njpegtran input.jpg | downstream\necho \"pipeline exit: $?\"","preventionTips":["Write to a file instead of stdout to avoid broken-pipe errors","Use 'set -o pipefail' in bash to catch pipeline failures","Ensure downstream consumers read the entire stream before exiting"],"tags":["jpeg","jpegtran","file-io","write-error","stdout","broken-pipe"],"backgroundTag":null,"analyzedSha":"45ab8f4308496e1f01026a97fcdb0d58a5274474","analyzedAt":"2026-08-14T05:19:30.815Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}