4 limits.c - manages data/functions for limiting the sizes of images read from files.
9 if (!i_set_image_file_limits(max_width, max_height, max_bytes)) {
12 i_get_image_file_limits(&max_width, &max_height, &max_bytes);
14 // file reader implementations
15 if (!i_int_check_image_file_limits(width, height, channels, sizeof(i_sample_t))) {
21 Manage limits for image files read by Imager.
23 Setting a value of zero means that limit will be ignored.
29 static int max_width, max_height;
33 i_set_image_file_limits(int width, int height, int bytes) {
37 i_push_error(0, "width must be non-negative");
41 i_push_error(0, "height must be non-negative");
45 i_push_error(0, "bytes must be non-negative");
57 i_get_image_file_limits(int *width, int *height, int *bytes) {
68 i_int_check_image_file_limits(int width, int height, int channels, int sample_size) {
73 i_push_errorf(0, "file size limit - image width of %d is not positive",
77 if (max_width && width > max_width) {
78 i_push_errorf(0, "file size limit - image width of %d exceeds limit of %d",
84 i_push_errorf(0, "file size limit - image height %d is not positive",
89 if (max_height && height > max_height) {
90 i_push_errorf(0, "file size limit - image height of %d "
91 "exceeds limit of %d", height, max_height);
95 if (channels < 1 || channels > MAXCHANNELS) {
96 i_push_errorf(0, "file size limit - channels %d out of range",
101 if (sample_size < 1 || sample_size > sizeof(long double)) {
102 i_push_errorf(0, "file size limit - sample_size %d out of range",
107 /* This overflow check is a bit more paranoid than usual.
108 We don't protect it under max_bytes since we always want to check
111 bytes = width * height * channels * sample_size;
112 if (bytes / width != height * channels * sample_size
113 || bytes / height != width * channels * sample_size) {
114 i_push_error(0, "file size limit - integer overflow calculating storage");
118 if (bytes > max_bytes) {
119 i_push_errorf(0, "file size limit - storage size of %d "
120 "exceeds limit of %d", bytes, max_bytes);