{"record":{"id":"8fa029d882360abe","repo":"DrKLO/Telegram","slug":"s-can-t-determine-size-of-s-8fa029","errorCode":null,"errorMessage":"%s: can't determine size of %s\n","messagePattern":"(.+?): can't determine size of (.+?)\n","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"TMessagesProj/jni/mozjpeg/jpegtran.c","lineNumber":512,"sourceCode":"    if ((fp = fopen(argv[file_index], READ_BINARY)) == NULL) {\n      fprintf(stderr, \"%s: can't open %s for reading\\n\", progname,\n              argv[file_index]);\n      exit(EXIT_FAILURE);\n    }\n  } else {\n    /* default input file is stdin */\n    fp = read_stdin();\n  }\n\n  if (icc_filename != NULL) {\n    if ((icc_file = fopen(icc_filename, READ_BINARY)) == NULL) {\n      fprintf(stderr, \"%s: can't open %s\\n\", progname, icc_filename);\n      exit(EXIT_FAILURE);\n    }\n    if (fseek(icc_file, 0, SEEK_END) < 0 ||\n        (icc_len = ftell(icc_file)) < 1 ||\n        fseek(icc_file, 0, SEEK_SET) < 0) {\n      fprintf(stderr, \"%s: can't determine size of %s\\n\", progname,\n              icc_filename);\n      exit(EXIT_FAILURE);\n    }\n    if ((icc_profile = (JOCTET *)malloc(icc_len)) == NULL) {\n      fprintf(stderr, \"%s: can't allocate memory for ICC profile\\n\", progname);\n      fclose(icc_file);\n      exit(EXIT_FAILURE);\n    }\n    if (fread(icc_profile, icc_len, 1, icc_file) < 1) {\n      fprintf(stderr, \"%s: can't read ICC profile from %s\\n\", progname,\n              icc_filename);\n      free(icc_profile);\n      fclose(icc_file);\n      exit(EXIT_FAILURE);\n    }\n    fclose(icc_file);\n    if (copyoption == JCOPYOPT_ALL)\n      copyoption = JCOPYOPT_ALL_EXCEPT_ICC;","sourceCodeStart":494,"sourceCodeEnd":530,"githubUrl":"https://github.com/DrKLO/Telegram/blob/45ab8f4308496e1f01026a97fcdb0d58a5274474/TMessagesProj/jni/mozjpeg/jpegtran.c#L494-L530","documentation":"After opening the ICC profile file, jpegtran determines its size via fseek(SEEK_END), ftell(), and fseek(SEEK_SET) at jpegtran.c:509-511. If any of these three calls fails or ftell returns less than 1, the file size cannot be determined. This typically happens when the ICC 'file' is not a regular seekable file.","triggerScenarios":"Passing a pipe, FIFO, socket, or /dev/stdin as the ICC profile path. A filesystem that doesn't support seeking. A file that was truncated to zero bytes between open and fseek.","commonSituations":"ICC profile is piped: `jpegtran -icc <(cat profile.icc)`. On Android, the path resolves to a special device file. The ICC file is on a network mount with interrupted connectivity.","solutions":["Ensure the ICC profile is a regular seekable file: `stat(icc_path)` and check S_ISREG(st_mode)","Copy the ICC profile to local storage (e.g. app internal dir) before passing it","If the data comes from a stream, write it to a temp file first, then pass that temp file path"],"exampleFix":"// before\n// icc_path is a pipe or FIFO\n\n// after\n// copy to a regular temp file first\nint fd = open(icc_tmp, O_CREAT|O_WRONLY, 0600);\nwrite(fd, icc_data, icc_data_len);\nclose(fd);\n// now pass icc_tmp to jpegtran -icc","handlingStrategy":"validation","validationCode":"// Ensure ICC file is a regular seekable file\nint validate_icc_seekable(const char *path) {\n    struct stat st;\n    if (stat(path, &st) != 0) return -1;\n    if (!S_ISREG(st.st_mode)) return -1; // reject pipes, FIFOs, devices\n    // verify it's seekable\n    FILE *f = fopen(path, \"rb\");\n    if (!f) return -1;\n    if (fseek(f, 0, SEEK_END) != 0) { fclose(f); return -1; }\n    long sz = ftell(f);\n    fclose(f);\n    if (sz < 1) return -1;\n    return 0;\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Never pipe an ICC profile; always use a regular file path","Copy stream-based ICC data to a temp file before passing to jpegtran","Verify S_ISREG via stat() before invoking jpegtran with -icc"],"tags":["jpeg","jpegtran","icc-profile","seekable-file","file-io"],"backgroundTag":null,"analyzedSha":"45ab8f4308496e1f01026a97fcdb0d58a5274474","analyzedAt":"2026-08-14T05:19:30.815Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}