{"record":{"id":"fa603f8642526011","repo":"DrKLO/Telegram","slug":"s-skip-region-exceeds-image-height-d-n","errorCode":null,"errorMessage":"%s: skip region exceeds image height %d\\n","messagePattern":"(.+?): skip region exceeds image height (.+?)\\\\n","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"TMessagesProj/jni/mozjpeg/djpeg.c","lineNumber":692,"sourceCode":"  default:\n    ERREXIT(&cinfo, JERR_UNSUPPORTED_FORMAT);\n    break;\n  }\n  dest_mgr->output_file = output_file;\n\n  /* Start decompressor */\n  (void)jpeg_start_decompress(&cinfo);\n\n  /* Skip rows */\n  if (skip) {\n    JDIMENSION tmp;\n\n    /* Check for valid skip_end.  We cannot check this value until after\n     * jpeg_start_decompress() is called.  Note that we have already verified\n     * that skip_start <= skip_end.\n     */\n    if (skip_end > cinfo.output_height - 1) {\n      fprintf(stderr, \"%s: skip region exceeds image height %d\\n\", progname,\n              cinfo.output_height);\n      exit(EXIT_FAILURE);\n    }\n\n    /* Write output file header.  This is a hack to ensure that the destination\n     * manager creates an output image of the proper size.\n     */\n    tmp = cinfo.output_height;\n    cinfo.output_height -= (skip_end - skip_start + 1);\n    (*dest_mgr->start_output) (&cinfo, dest_mgr);\n    cinfo.output_height = tmp;\n\n    /* Process data */\n    while (cinfo.output_scanline < skip_start) {\n      num_scanlines = jpeg_read_scanlines(&cinfo, dest_mgr->buffer,\n                                          dest_mgr->buffer_height);\n      (*dest_mgr->put_pixel_rows) (&cinfo, dest_mgr, num_scanlines);\n    }","sourceCodeStart":674,"sourceCodeEnd":710,"githubUrl":"https://github.com/DrKLO/Telegram/blob/45ab8f4308496e1f01026a97fcdb0d58a5274474/TMessagesProj/jni/mozjpeg/djpeg.c#L674-L710","documentation":"The -skip option specified a skip region whose end row (skip_end) exceeds the image's actual output height (output_height - 1). This check runs after jpeg_start_decompress(), because output_height is only valid then. The program exits with failure; it is fatal.","triggerScenarios":"Passing -skip WxH or -skip start-end where skip_end is greater than or equal to the decompressed image height. The exact bound is checked post-start-decompress, so the error surfaces only at runtime once the JPEG header reveals the true dimensions.","commonSituations":"Hardcoding skip values from a different (larger) image, decoding a downsampled/rotated variant where height differs, or a JPEG whose dimensions changed after a previous transform pass.","solutions":["Query the image height first (jpeg_read_header then read output_height) and compute skip_end from actual dimensions.","Clamp skip_end to output_height - 1 before passing the -skip argument.","Re-derive skip parameters from the current JPEG rather than reusing constants from another image.","Validate skip_start <= skip_end < output_height in your wrapper before invoking djpeg."],"exampleFix":"// before\n./djpeg -skip 0-9999 small.jpg > out.ppm\n// after: clamp to actual height\nH=$(jpeginfo -h small.jpg)  # or read via jpeg_read_header\nEND=$((H - 1))\n./djpeg -skip 0-$END small.jpg > out.ppm","handlingStrategy":"validation","validationCode":"#include <jpeglib.h>\n/* after jpeg_read_header + jpeg_start_decompress, validate skip */\nint skip_ok(j_decompress_ptr c, int skip_start, int skip_end) {\n  return skip_start <= skip_end && skip_end <= (int)c->output_height - 1;\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always derive skip_end from the actual output_height at runtime.","Clamp skip_end to output_height - 1 in the wrapper.","Never hardcode skip values across different images."],"tags":["djpeg","skip","geometry","validation","mozjpeg"],"backgroundTag":null,"analyzedSha":"45ab8f4308496e1f01026a97fcdb0d58a5274474","analyzedAt":"2026-08-14T05:19:30.815Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}