diff options
| author | Paul Eggert | 2011-07-28 09:27:30 -0700 |
|---|---|---|
| committer | Paul Eggert | 2011-07-28 09:27:30 -0700 |
| commit | 70c2e72ae5368e39277de78a414c9d42292886c5 (patch) | |
| tree | dc2f35bb271058a7dc728ef970da93db9a48b2ff /src/image.c | |
| parent | f13cae31f1beecc4f3fd39e4aa4bcb9fc8d9e7c1 (diff) | |
| parent | 58e9b49a90338bf979b86951b6d85e60308ecc3e (diff) | |
| download | emacs-70c2e72ae5368e39277de78a414c9d42292886c5.tar.gz emacs-70c2e72ae5368e39277de78a414c9d42292886c5.zip | |
Merge from trunk.
Diffstat (limited to 'src/image.c')
| -rw-r--r-- | src/image.c | 236 |
1 files changed, 150 insertions, 86 deletions
diff --git a/src/image.c b/src/image.c index fa39ff12681..fb1d825fa54 100644 --- a/src/image.c +++ b/src/image.c | |||
| @@ -136,7 +136,6 @@ static unsigned long lookup_rgb_color (struct frame *f, int r, int g, int b); | |||
| 136 | #ifdef COLOR_TABLE_SUPPORT | 136 | #ifdef COLOR_TABLE_SUPPORT |
| 137 | static void free_color_table (void); | 137 | static void free_color_table (void); |
| 138 | static unsigned long *colors_in_color_table (int *n); | 138 | static unsigned long *colors_in_color_table (int *n); |
| 139 | static unsigned long lookup_pixel_color (struct frame *f, unsigned long p); | ||
| 140 | #endif | 139 | #endif |
| 141 | static Lisp_Object Finit_image_library (Lisp_Object, Lisp_Object); | 140 | static Lisp_Object Finit_image_library (Lisp_Object, Lisp_Object); |
| 142 | 141 | ||
| @@ -987,7 +986,6 @@ or omitted means use the selected frame. */) | |||
| 987 | ***********************************************************************/ | 986 | ***********************************************************************/ |
| 988 | 987 | ||
| 989 | static void free_image (struct frame *f, struct image *img); | 988 | static void free_image (struct frame *f, struct image *img); |
| 990 | static int check_image_size (struct frame *f, int width, int height); | ||
| 991 | 989 | ||
| 992 | #define MAX_IMAGE_SIZE 6.0 | 990 | #define MAX_IMAGE_SIZE 6.0 |
| 993 | /* Allocate and return a new image structure for image specification | 991 | /* Allocate and return a new image structure for image specification |
| @@ -1042,7 +1040,7 @@ free_image (struct frame *f, struct image *img) | |||
| 1042 | /* Return 1 if the given widths and heights are valid for display; | 1040 | /* Return 1 if the given widths and heights are valid for display; |
| 1043 | otherwise, return 0. */ | 1041 | otherwise, return 0. */ |
| 1044 | 1042 | ||
| 1045 | int | 1043 | static int |
| 1046 | check_image_size (struct frame *f, int width, int height) | 1044 | check_image_size (struct frame *f, int width, int height) |
| 1047 | { | 1045 | { |
| 1048 | int w, h; | 1046 | int w, h; |
| @@ -1051,23 +1049,18 @@ check_image_size (struct frame *f, int width, int height) | |||
| 1051 | return 0; | 1049 | return 0; |
| 1052 | 1050 | ||
| 1053 | if (INTEGERP (Vmax_image_size)) | 1051 | if (INTEGERP (Vmax_image_size)) |
| 1054 | w = h = XINT (Vmax_image_size); | 1052 | return (width <= XINT (Vmax_image_size) |
| 1053 | && height <= XINT (Vmax_image_size)); | ||
| 1055 | else if (FLOATP (Vmax_image_size)) | 1054 | else if (FLOATP (Vmax_image_size)) |
| 1056 | { | 1055 | { |
| 1057 | if (f != NULL) | 1056 | xassert (f); |
| 1058 | { | 1057 | w = FRAME_PIXEL_WIDTH (f); |
| 1059 | w = FRAME_PIXEL_WIDTH (f); | 1058 | h = FRAME_PIXEL_HEIGHT (f); |
| 1060 | h = FRAME_PIXEL_HEIGHT (f); | 1059 | return (width <= XFLOAT_DATA (Vmax_image_size) * w |
| 1061 | } | 1060 | && height <= XFLOAT_DATA (Vmax_image_size) * h); |
| 1062 | else | ||
| 1063 | w = h = 1024; /* Arbitrary size for unknown frame. */ | ||
| 1064 | w = (int) (XFLOAT_DATA (Vmax_image_size) * w); | ||
| 1065 | h = (int) (XFLOAT_DATA (Vmax_image_size) * h); | ||
| 1066 | } | 1061 | } |
| 1067 | else | 1062 | else |
| 1068 | return 1; | 1063 | return 1; |
| 1069 | |||
| 1070 | return (width <= w && height <= h); | ||
| 1071 | } | 1064 | } |
| 1072 | 1065 | ||
| 1073 | /* Prepare image IMG for display on frame F. Must be called before | 1066 | /* Prepare image IMG for display on frame F. Must be called before |
| @@ -1368,7 +1361,9 @@ x_alloc_image_color (struct frame *f, struct image *img, Lisp_Object color_name, | |||
| 1368 | 1361 | ||
| 1369 | xassert (STRINGP (color_name)); | 1362 | xassert (STRINGP (color_name)); |
| 1370 | 1363 | ||
| 1371 | if (x_defined_color (f, SSDATA (color_name), &color, 1)) | 1364 | if (x_defined_color (f, SSDATA (color_name), &color, 1) |
| 1365 | && img->ncolors < min (min (PTRDIFF_MAX, SIZE_MAX) / sizeof *img->colors, | ||
| 1366 | INT_MAX)) | ||
| 1372 | { | 1367 | { |
| 1373 | /* This isn't called frequently so we get away with simply | 1368 | /* This isn't called frequently so we get away with simply |
| 1374 | reallocating the color vector to the needed size, here. */ | 1369 | reallocating the color vector to the needed size, here. */ |
| @@ -1911,6 +1906,44 @@ static int x_create_x_image_and_pixmap (struct frame *, int, int, int, | |||
| 1911 | static void x_destroy_x_image (XImagePtr); | 1906 | static void x_destroy_x_image (XImagePtr); |
| 1912 | static void x_put_x_image (struct frame *, XImagePtr, Pixmap, int, int); | 1907 | static void x_put_x_image (struct frame *, XImagePtr, Pixmap, int, int); |
| 1913 | 1908 | ||
| 1909 | /* Return nonzero if XIMG's size WIDTH x HEIGHT doesn't break the | ||
| 1910 | windowing system. | ||
| 1911 | WIDTH and HEIGHT must both be positive. | ||
| 1912 | If XIMG is null, assume it is a bitmap. */ | ||
| 1913 | static int | ||
| 1914 | x_check_image_size (XImagePtr ximg, int width, int height) | ||
| 1915 | { | ||
| 1916 | #ifdef HAVE_X_WINDOWS | ||
| 1917 | /* Respect Xlib's limits: it cannot deal with images that have more | ||
| 1918 | than INT_MAX (and/or UINT_MAX) bytes. And respect Emacs's limits | ||
| 1919 | of PTRDIFF_MAX (and/or SIZE_MAX) bytes for any object. */ | ||
| 1920 | enum | ||
| 1921 | { | ||
| 1922 | XLIB_BYTES_MAX = min (INT_MAX, UINT_MAX), | ||
| 1923 | X_IMAGE_BYTES_MAX = min (XLIB_BYTES_MAX, min (PTRDIFF_MAX, SIZE_MAX)) | ||
| 1924 | }; | ||
| 1925 | |||
| 1926 | int bitmap_pad, depth, bytes_per_line; | ||
| 1927 | if (ximg) | ||
| 1928 | { | ||
| 1929 | bitmap_pad = ximg->bitmap_pad; | ||
| 1930 | depth = ximg->depth; | ||
| 1931 | bytes_per_line = ximg->bytes_per_line; | ||
| 1932 | } | ||
| 1933 | else | ||
| 1934 | { | ||
| 1935 | bitmap_pad = 8; | ||
| 1936 | depth = 1; | ||
| 1937 | bytes_per_line = (width >> 3) + ((width & 7) != 0); | ||
| 1938 | } | ||
| 1939 | return (width <= (INT_MAX - (bitmap_pad - 1)) / depth | ||
| 1940 | && height <= X_IMAGE_BYTES_MAX / bytes_per_line); | ||
| 1941 | #else | ||
| 1942 | /* FIXME: Implement this check for the HAVE_NS and HAVE_NTGUI cases. | ||
| 1943 | For now, assume that every image size is allowed on these systems. */ | ||
| 1944 | return 1; | ||
| 1945 | #endif | ||
| 1946 | } | ||
| 1914 | 1947 | ||
| 1915 | /* Create an XImage and a pixmap of size WIDTH x HEIGHT for use on | 1948 | /* Create an XImage and a pixmap of size WIDTH x HEIGHT for use on |
| 1916 | frame F. Set *XIMG and *PIXMAP to the XImage and Pixmap created. | 1949 | frame F. Set *XIMG and *PIXMAP to the XImage and Pixmap created. |
| @@ -1943,6 +1976,15 @@ x_create_x_image_and_pixmap (struct frame *f, int width, int height, int depth, | |||
| 1943 | return 0; | 1976 | return 0; |
| 1944 | } | 1977 | } |
| 1945 | 1978 | ||
| 1979 | if (! x_check_image_size (*ximg, width, height)) | ||
| 1980 | { | ||
| 1981 | x_destroy_x_image (*ximg); | ||
| 1982 | *ximg = NULL; | ||
| 1983 | image_error ("Image too large (%dx%d)", | ||
| 1984 | make_number (width), make_number (height)); | ||
| 1985 | return 0; | ||
| 1986 | } | ||
| 1987 | |||
| 1946 | /* Allocate image raster. */ | 1988 | /* Allocate image raster. */ |
| 1947 | (*ximg)->data = (char *) xmalloc ((*ximg)->bytes_per_line * height); | 1989 | (*ximg)->data = (char *) xmalloc ((*ximg)->bytes_per_line * height); |
| 1948 | 1990 | ||
| @@ -1989,11 +2031,6 @@ x_create_x_image_and_pixmap (struct frame *f, int width, int height, int depth, | |||
| 1989 | palette_colors = 1 << depth - 1; | 2031 | palette_colors = 1 << depth - 1; |
| 1990 | 2032 | ||
| 1991 | *ximg = xmalloc (sizeof (XImage) + palette_colors * sizeof (RGBQUAD)); | 2033 | *ximg = xmalloc (sizeof (XImage) + palette_colors * sizeof (RGBQUAD)); |
| 1992 | if (*ximg == NULL) | ||
| 1993 | { | ||
| 1994 | image_error ("Unable to allocate memory for XImage", Qnil, Qnil); | ||
| 1995 | return 0; | ||
| 1996 | } | ||
| 1997 | 2034 | ||
| 1998 | header = &(*ximg)->info.bmiHeader; | 2035 | header = &(*ximg)->info.bmiHeader; |
| 1999 | memset (&(*ximg)->info, 0, sizeof (BITMAPINFO)); | 2036 | memset (&(*ximg)->info, 0, sizeof (BITMAPINFO)); |
| @@ -2365,7 +2402,7 @@ xbm_image_p (Lisp_Object object) | |||
| 2365 | } | 2402 | } |
| 2366 | else if (BOOL_VECTOR_P (data)) | 2403 | else if (BOOL_VECTOR_P (data)) |
| 2367 | { | 2404 | { |
| 2368 | if (XBOOL_VECTOR (data)->size < width * height) | 2405 | if (XBOOL_VECTOR (data)->size / height < width) |
| 2369 | return 0; | 2406 | return 0; |
| 2370 | } | 2407 | } |
| 2371 | else | 2408 | else |
| @@ -2561,13 +2598,15 @@ Create_Pixmap_From_Bitmap_Data (struct frame *f, struct image *img, char *data, | |||
| 2561 | img->pixmap = ns_image_from_XBM (data, img->width, img->height); | 2598 | img->pixmap = ns_image_from_XBM (data, img->width, img->height); |
| 2562 | 2599 | ||
| 2563 | #else | 2600 | #else |
| 2564 | img->pixmap | 2601 | img->pixmap = |
| 2565 | = XCreatePixmapFromBitmapData (FRAME_X_DISPLAY (f), | 2602 | (x_check_image_size (0, img->width, img->height) |
| 2603 | ? XCreatePixmapFromBitmapData (FRAME_X_DISPLAY (f), | ||
| 2566 | FRAME_X_WINDOW (f), | 2604 | FRAME_X_WINDOW (f), |
| 2567 | data, | 2605 | data, |
| 2568 | img->width, img->height, | 2606 | img->width, img->height, |
| 2569 | fg, bg, | 2607 | fg, bg, |
| 2570 | DefaultDepthOfScreen (FRAME_X_SCREEN (f))); | 2608 | DefaultDepthOfScreen (FRAME_X_SCREEN (f))) |
| 2609 | : NO_PIXMAP); | ||
| 2571 | #endif /* !HAVE_NTGUI && !HAVE_NS */ | 2610 | #endif /* !HAVE_NTGUI && !HAVE_NS */ |
| 2572 | } | 2611 | } |
| 2573 | 2612 | ||
| @@ -2674,6 +2713,13 @@ xbm_read_bitmap_data (struct frame *f, unsigned char *contents, unsigned char *e | |||
| 2674 | expect ('='); | 2713 | expect ('='); |
| 2675 | expect ('{'); | 2714 | expect ('{'); |
| 2676 | 2715 | ||
| 2716 | if (! x_check_image_size (0, *width, *height)) | ||
| 2717 | { | ||
| 2718 | if (!inhibit_image_error) | ||
| 2719 | image_error ("Image too large (%dx%d)", | ||
| 2720 | make_number (*width), make_number (*height)); | ||
| 2721 | goto failure; | ||
| 2722 | } | ||
| 2677 | bytes_per_line = (*width + 7) / 8 + padding_p; | 2723 | bytes_per_line = (*width + 7) / 8 + padding_p; |
| 2678 | nbytes = bytes_per_line * *height; | 2724 | nbytes = bytes_per_line * *height; |
| 2679 | p = *data = (char *) xmalloc (nbytes); | 2725 | p = *data = (char *) xmalloc (nbytes); |
| @@ -2864,6 +2910,12 @@ xbm_load (struct frame *f, struct image *img) | |||
| 2864 | img->width = XFASTINT (fmt[XBM_WIDTH].value); | 2910 | img->width = XFASTINT (fmt[XBM_WIDTH].value); |
| 2865 | img->height = XFASTINT (fmt[XBM_HEIGHT].value); | 2911 | img->height = XFASTINT (fmt[XBM_HEIGHT].value); |
| 2866 | xassert (img->width > 0 && img->height > 0); | 2912 | xassert (img->width > 0 && img->height > 0); |
| 2913 | if (!check_image_size (f, img->width, img->height)) | ||
| 2914 | { | ||
| 2915 | image_error ("Invalid image size (see `max-image-size')", | ||
| 2916 | Qnil, Qnil); | ||
| 2917 | return 0; | ||
| 2918 | } | ||
| 2867 | } | 2919 | } |
| 2868 | 2920 | ||
| 2869 | /* Get foreground and background colors, maybe allocate colors. */ | 2921 | /* Get foreground and background colors, maybe allocate colors. */ |
| @@ -2925,9 +2977,13 @@ xbm_load (struct frame *f, struct image *img) | |||
| 2925 | #endif | 2977 | #endif |
| 2926 | /* Create the pixmap. */ | 2978 | /* Create the pixmap. */ |
| 2927 | 2979 | ||
| 2928 | Create_Pixmap_From_Bitmap_Data (f, img, bits, | 2980 | if (x_check_image_size (0, img->width, img->height)) |
| 2929 | foreground, background, | 2981 | Create_Pixmap_From_Bitmap_Data (f, img, bits, |
| 2930 | non_default_colors); | 2982 | foreground, background, |
| 2983 | non_default_colors); | ||
| 2984 | else | ||
| 2985 | img->pixmap = NO_PIXMAP; | ||
| 2986 | |||
| 2931 | if (img->pixmap) | 2987 | if (img->pixmap) |
| 2932 | success_p = 1; | 2988 | success_p = 1; |
| 2933 | else | 2989 | else |
| @@ -3125,12 +3181,8 @@ xpm_free_color_cache (void) | |||
| 3125 | static int | 3181 | static int |
| 3126 | xpm_color_bucket (char *color_name) | 3182 | xpm_color_bucket (char *color_name) |
| 3127 | { | 3183 | { |
| 3128 | unsigned h = 0; | 3184 | EMACS_UINT hash = hash_string (color_name, strlen (color_name)); |
| 3129 | char *s; | 3185 | return hash % XPM_COLOR_CACHE_BUCKETS; |
| 3130 | |||
| 3131 | for (s = color_name; *s; ++s) | ||
| 3132 | h = (h << 2) ^ *s; | ||
| 3133 | return h %= XPM_COLOR_CACHE_BUCKETS; | ||
| 3134 | } | 3186 | } |
| 3135 | 3187 | ||
| 3136 | 3188 | ||
| @@ -3147,7 +3199,7 @@ xpm_cache_color (struct frame *f, char *color_name, XColor *color, int bucket) | |||
| 3147 | if (bucket < 0) | 3199 | if (bucket < 0) |
| 3148 | bucket = xpm_color_bucket (color_name); | 3200 | bucket = xpm_color_bucket (color_name); |
| 3149 | 3201 | ||
| 3150 | nbytes = sizeof *p + strlen (color_name); | 3202 | nbytes = offsetof (struct xpm_cached_color, name) + strlen (color_name) + 1; |
| 3151 | p = (struct xpm_cached_color *) xmalloc (nbytes); | 3203 | p = (struct xpm_cached_color *) xmalloc (nbytes); |
| 3152 | strcpy (p->name, color_name); | 3204 | strcpy (p->name, color_name); |
| 3153 | p->color = *color; | 3205 | p->color = *color; |
| @@ -3849,6 +3901,18 @@ xpm_load_image (struct frame *f, | |||
| 3849 | goto failure; | 3901 | goto failure; |
| 3850 | } | 3902 | } |
| 3851 | 3903 | ||
| 3904 | if (!x_create_x_image_and_pixmap (f, width, height, 0, | ||
| 3905 | &ximg, &img->pixmap) | ||
| 3906 | #ifndef HAVE_NS | ||
| 3907 | || !x_create_x_image_and_pixmap (f, width, height, 1, | ||
| 3908 | &mask_img, &img->mask) | ||
| 3909 | #endif | ||
| 3910 | ) | ||
| 3911 | { | ||
| 3912 | image_error ("Image too large", Qnil, Qnil); | ||
| 3913 | goto failure; | ||
| 3914 | } | ||
| 3915 | |||
| 3852 | expect (','); | 3916 | expect (','); |
| 3853 | 3917 | ||
| 3854 | XSETFRAME (frame, f); | 3918 | XSETFRAME (frame, f); |
| @@ -3942,18 +4006,6 @@ xpm_load_image (struct frame *f, | |||
| 3942 | expect (','); | 4006 | expect (','); |
| 3943 | } | 4007 | } |
| 3944 | 4008 | ||
| 3945 | if (!x_create_x_image_and_pixmap (f, width, height, 0, | ||
| 3946 | &ximg, &img->pixmap) | ||
| 3947 | #ifndef HAVE_NS | ||
| 3948 | || !x_create_x_image_and_pixmap (f, width, height, 1, | ||
| 3949 | &mask_img, &img->mask) | ||
| 3950 | #endif | ||
| 3951 | ) | ||
| 3952 | { | ||
| 3953 | image_error ("Out of memory (%s)", img->spec, Qnil); | ||
| 3954 | goto error; | ||
| 3955 | } | ||
| 3956 | |||
| 3957 | for (y = 0; y < height; y++) | 4009 | for (y = 0; y < height; y++) |
| 3958 | { | 4010 | { |
| 3959 | expect (XPM_TK_STRING); | 4011 | expect (XPM_TK_STRING); |
| @@ -5518,8 +5570,8 @@ my_png_warning (png_struct *png_ptr, const char *msg) | |||
| 5518 | struct png_memory_storage | 5570 | struct png_memory_storage |
| 5519 | { | 5571 | { |
| 5520 | unsigned char *bytes; /* The data */ | 5572 | unsigned char *bytes; /* The data */ |
| 5521 | size_t len; /* How big is it? */ | 5573 | ptrdiff_t len; /* How big is it? */ |
| 5522 | int index; /* Where are we? */ | 5574 | ptrdiff_t index; /* Where are we? */ |
| 5523 | }; | 5575 | }; |
| 5524 | 5576 | ||
| 5525 | 5577 | ||
| @@ -5563,7 +5615,8 @@ png_load (struct frame *f, struct image *img) | |||
| 5563 | { | 5615 | { |
| 5564 | Lisp_Object file, specified_file; | 5616 | Lisp_Object file, specified_file; |
| 5565 | Lisp_Object specified_data; | 5617 | Lisp_Object specified_data; |
| 5566 | int x, y, i; | 5618 | int x, y; |
| 5619 | ptrdiff_t i; | ||
| 5567 | XImagePtr ximg, mask_img = NULL; | 5620 | XImagePtr ximg, mask_img = NULL; |
| 5568 | png_struct *png_ptr = NULL; | 5621 | png_struct *png_ptr = NULL; |
| 5569 | png_info *info_ptr = NULL, *end_info = NULL; | 5622 | png_info *info_ptr = NULL, *end_info = NULL; |
| @@ -5683,11 +5736,19 @@ png_load (struct frame *f, struct image *img) | |||
| 5683 | fn_png_get_IHDR (png_ptr, info_ptr, &width, &height, &bit_depth, &color_type, | 5736 | fn_png_get_IHDR (png_ptr, info_ptr, &width, &height, &bit_depth, &color_type, |
| 5684 | &interlace_type, NULL, NULL); | 5737 | &interlace_type, NULL, NULL); |
| 5685 | 5738 | ||
| 5686 | if (!check_image_size (f, width, height)) | 5739 | if (! (width <= INT_MAX && height <= INT_MAX |
| 5740 | && check_image_size (f, width, height))) | ||
| 5687 | { | 5741 | { |
| 5688 | image_error ("Invalid image size (see `max-image-size')", Qnil, Qnil); | 5742 | image_error ("Invalid image size (see `max-image-size')", Qnil, Qnil); |
| 5689 | goto error; | 5743 | goto error; |
| 5690 | } | 5744 | } |
| 5745 | |||
| 5746 | /* Create the X image and pixmap now, so that the work below can be | ||
| 5747 | omitted if the image is too large for X. */ | ||
| 5748 | if (!x_create_x_image_and_pixmap (f, width, height, 0, &ximg, | ||
| 5749 | &img->pixmap)) | ||
| 5750 | goto error; | ||
| 5751 | |||
| 5691 | /* If image contains simply transparency data, we prefer to | 5752 | /* If image contains simply transparency data, we prefer to |
| 5692 | construct a clipping mask. */ | 5753 | construct a clipping mask. */ |
| 5693 | if (fn_png_get_valid (png_ptr, info_ptr, PNG_INFO_tRNS)) | 5754 | if (fn_png_get_valid (png_ptr, info_ptr, PNG_INFO_tRNS)) |
| @@ -5776,7 +5837,10 @@ png_load (struct frame *f, struct image *img) | |||
| 5776 | row_bytes = fn_png_get_rowbytes (png_ptr, info_ptr); | 5837 | row_bytes = fn_png_get_rowbytes (png_ptr, info_ptr); |
| 5777 | 5838 | ||
| 5778 | /* Allocate memory for the image. */ | 5839 | /* Allocate memory for the image. */ |
| 5779 | pixels = (png_byte *) xmalloc (row_bytes * height * sizeof *pixels); | 5840 | if (min (PTRDIFF_MAX, SIZE_MAX) / sizeof *rows < height |
| 5841 | || min (PTRDIFF_MAX, SIZE_MAX) / sizeof *pixels / height < row_bytes) | ||
| 5842 | memory_full (SIZE_MAX); | ||
| 5843 | pixels = (png_byte *) xmalloc (sizeof *pixels * row_bytes * height); | ||
| 5780 | rows = (png_byte **) xmalloc (height * sizeof *rows); | 5844 | rows = (png_byte **) xmalloc (height * sizeof *rows); |
| 5781 | for (i = 0; i < height; ++i) | 5845 | for (i = 0; i < height; ++i) |
| 5782 | rows[i] = pixels + i * row_bytes; | 5846 | rows[i] = pixels + i * row_bytes; |
| @@ -5790,11 +5854,6 @@ png_load (struct frame *f, struct image *img) | |||
| 5790 | fp = NULL; | 5854 | fp = NULL; |
| 5791 | } | 5855 | } |
| 5792 | 5856 | ||
| 5793 | /* Create the X image and pixmap. */ | ||
| 5794 | if (!x_create_x_image_and_pixmap (f, width, height, 0, &ximg, | ||
| 5795 | &img->pixmap)) | ||
| 5796 | goto error; | ||
| 5797 | |||
| 5798 | /* Create an image and pixmap serving as mask if the PNG image | 5857 | /* Create an image and pixmap serving as mask if the PNG image |
| 5799 | contains an alpha channel. */ | 5858 | contains an alpha channel. */ |
| 5800 | if (channels == 4 | 5859 | if (channels == 4 |
| @@ -6192,7 +6251,7 @@ our_stdio_fill_input_buffer (j_decompress_ptr cinfo) | |||
| 6192 | src = (struct jpeg_stdio_mgr *) cinfo->src; | 6251 | src = (struct jpeg_stdio_mgr *) cinfo->src; |
| 6193 | if (!src->finished) | 6252 | if (!src->finished) |
| 6194 | { | 6253 | { |
| 6195 | size_t bytes; | 6254 | ptrdiff_t bytes; |
| 6196 | 6255 | ||
| 6197 | bytes = fread (src->buffer, 1, JPEG_STDIO_BUFFER_SIZE, src->file); | 6256 | bytes = fread (src->buffer, 1, JPEG_STDIO_BUFFER_SIZE, src->file); |
| 6198 | if (bytes > 0) | 6257 | if (bytes > 0) |
| @@ -6602,34 +6661,33 @@ init_tiff_functions (Lisp_Object libraries) | |||
| 6602 | typedef struct | 6661 | typedef struct |
| 6603 | { | 6662 | { |
| 6604 | unsigned char *bytes; | 6663 | unsigned char *bytes; |
| 6605 | size_t len; | 6664 | ptrdiff_t len; |
| 6606 | int index; | 6665 | ptrdiff_t index; |
| 6607 | } | 6666 | } |
| 6608 | tiff_memory_source; | 6667 | tiff_memory_source; |
| 6609 | 6668 | ||
| 6610 | static size_t | 6669 | static tsize_t |
| 6611 | tiff_read_from_memory (thandle_t data, tdata_t buf, tsize_t size) | 6670 | tiff_read_from_memory (thandle_t data, tdata_t buf, tsize_t size) |
| 6612 | { | 6671 | { |
| 6613 | tiff_memory_source *src = (tiff_memory_source *) data; | 6672 | tiff_memory_source *src = (tiff_memory_source *) data; |
| 6614 | 6673 | ||
| 6615 | if (size > src->len - src->index) | 6674 | size = min (size, src->len - src->index); |
| 6616 | return (size_t) -1; | ||
| 6617 | memcpy (buf, src->bytes + src->index, size); | 6675 | memcpy (buf, src->bytes + src->index, size); |
| 6618 | src->index += size; | 6676 | src->index += size; |
| 6619 | return size; | 6677 | return size; |
| 6620 | } | 6678 | } |
| 6621 | 6679 | ||
| 6622 | static size_t | 6680 | static tsize_t |
| 6623 | tiff_write_from_memory (thandle_t data, tdata_t buf, tsize_t size) | 6681 | tiff_write_from_memory (thandle_t data, tdata_t buf, tsize_t size) |
| 6624 | { | 6682 | { |
| 6625 | return (size_t) -1; | 6683 | return -1; |
| 6626 | } | 6684 | } |
| 6627 | 6685 | ||
| 6628 | static toff_t | 6686 | static toff_t |
| 6629 | tiff_seek_in_memory (thandle_t data, toff_t off, int whence) | 6687 | tiff_seek_in_memory (thandle_t data, toff_t off, int whence) |
| 6630 | { | 6688 | { |
| 6631 | tiff_memory_source *src = (tiff_memory_source *) data; | 6689 | tiff_memory_source *src = (tiff_memory_source *) data; |
| 6632 | int idx; | 6690 | ptrdiff_t idx; |
| 6633 | 6691 | ||
| 6634 | switch (whence) | 6692 | switch (whence) |
| 6635 | { | 6693 | { |
| @@ -6765,8 +6823,8 @@ tiff_load (struct frame *f, struct image *img) | |||
| 6765 | memsrc.index = 0; | 6823 | memsrc.index = 0; |
| 6766 | 6824 | ||
| 6767 | tiff = fn_TIFFClientOpen ("memory_source", "r", (thandle_t)&memsrc, | 6825 | tiff = fn_TIFFClientOpen ("memory_source", "r", (thandle_t)&memsrc, |
| 6768 | (TIFFReadWriteProc) tiff_read_from_memory, | 6826 | tiff_read_from_memory, |
| 6769 | (TIFFReadWriteProc) tiff_write_from_memory, | 6827 | tiff_write_from_memory, |
| 6770 | tiff_seek_in_memory, | 6828 | tiff_seek_in_memory, |
| 6771 | tiff_close_memory, | 6829 | tiff_close_memory, |
| 6772 | tiff_size_of_memory, | 6830 | tiff_size_of_memory, |
| @@ -6805,7 +6863,16 @@ tiff_load (struct frame *f, struct image *img) | |||
| 6805 | return 0; | 6863 | return 0; |
| 6806 | } | 6864 | } |
| 6807 | 6865 | ||
| 6808 | buf = (uint32 *) xmalloc (width * height * sizeof *buf); | 6866 | /* Create the X image and pixmap. */ |
| 6867 | if (! (height <= min (PTRDIFF_MAX, SIZE_MAX) / sizeof *buf / width | ||
| 6868 | && x_create_x_image_and_pixmap (f, width, height, 0, | ||
| 6869 | &ximg, &img->pixmap))) | ||
| 6870 | { | ||
| 6871 | fn_TIFFClose (tiff); | ||
| 6872 | return 0; | ||
| 6873 | } | ||
| 6874 | |||
| 6875 | buf = (uint32 *) xmalloc (sizeof *buf * width * height); | ||
| 6809 | 6876 | ||
| 6810 | rc = fn_TIFFReadRGBAImage (tiff, width, height, buf, 0); | 6877 | rc = fn_TIFFReadRGBAImage (tiff, width, height, buf, 0); |
| 6811 | 6878 | ||
| @@ -6826,13 +6893,6 @@ tiff_load (struct frame *f, struct image *img) | |||
| 6826 | return 0; | 6893 | return 0; |
| 6827 | } | 6894 | } |
| 6828 | 6895 | ||
| 6829 | /* Create the X image and pixmap. */ | ||
| 6830 | if (!x_create_x_image_and_pixmap (f, width, height, 0, &ximg, &img->pixmap)) | ||
| 6831 | { | ||
| 6832 | xfree (buf); | ||
| 6833 | return 0; | ||
| 6834 | } | ||
| 6835 | |||
| 6836 | /* Initialize the color table. */ | 6896 | /* Initialize the color table. */ |
| 6837 | init_color_table (); | 6897 | init_color_table (); |
| 6838 | 6898 | ||
| @@ -7034,8 +7094,8 @@ init_gif_functions (Lisp_Object libraries) | |||
| 7034 | typedef struct | 7094 | typedef struct |
| 7035 | { | 7095 | { |
| 7036 | unsigned char *bytes; | 7096 | unsigned char *bytes; |
| 7037 | size_t len; | 7097 | ptrdiff_t len; |
| 7038 | int index; | 7098 | ptrdiff_t index; |
| 7039 | } | 7099 | } |
| 7040 | gif_memory_source; | 7100 | gif_memory_source; |
| 7041 | 7101 | ||
| @@ -7668,7 +7728,8 @@ imagemagick_load_image (struct frame *f, struct image *img, | |||
| 7668 | height = MagickGetImageHeight (image_wand); | 7728 | height = MagickGetImageHeight (image_wand); |
| 7669 | width = MagickGetImageWidth (image_wand); | 7729 | width = MagickGetImageWidth (image_wand); |
| 7670 | 7730 | ||
| 7671 | if (! check_image_size (f, width, height)) | 7731 | if (! (width <= INT_MAX && height <= INT_MAX |
| 7732 | && check_image_size (f, width, height))) | ||
| 7672 | { | 7733 | { |
| 7673 | image_error ("Invalid image size (see `max-image-size')", Qnil, Qnil); | 7734 | image_error ("Invalid image size (see `max-image-size')", Qnil, Qnil); |
| 7674 | goto imagemagick_error; | 7735 | goto imagemagick_error; |
| @@ -7872,7 +7933,7 @@ recognize as images, such as C. See `imagemagick-types-inhibit'. */) | |||
| 7872 | size_t numf = 0; | 7933 | size_t numf = 0; |
| 7873 | ExceptionInfo ex; | 7934 | ExceptionInfo ex; |
| 7874 | char **imtypes = GetMagickList ("*", &numf, &ex); | 7935 | char **imtypes = GetMagickList ("*", &numf, &ex); |
| 7875 | int i; | 7936 | size_t i; |
| 7876 | Lisp_Object Qimagemagicktype; | 7937 | Lisp_Object Qimagemagicktype; |
| 7877 | for (i = 0; i < numf; i++) | 7938 | for (i = 0; i < numf; i++) |
| 7878 | { | 7939 | { |
| @@ -8426,12 +8487,15 @@ gs_load (struct frame *f, struct image *img) | |||
| 8426 | /* Create the pixmap. */ | 8487 | /* Create the pixmap. */ |
| 8427 | xassert (img->pixmap == NO_PIXMAP); | 8488 | xassert (img->pixmap == NO_PIXMAP); |
| 8428 | 8489 | ||
| 8429 | /* Only W32 version did BLOCK_INPUT here. ++kfs */ | 8490 | if (x_check_image_size (0, img->width, img->height)) |
| 8430 | BLOCK_INPUT; | 8491 | { |
| 8431 | img->pixmap = XCreatePixmap (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f), | 8492 | /* Only W32 version did BLOCK_INPUT here. ++kfs */ |
| 8432 | img->width, img->height, | 8493 | BLOCK_INPUT; |
| 8433 | DefaultDepthOfScreen (FRAME_X_SCREEN (f))); | 8494 | img->pixmap = XCreatePixmap (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f), |
| 8434 | UNBLOCK_INPUT; | 8495 | img->width, img->height, |
| 8496 | DefaultDepthOfScreen (FRAME_X_SCREEN (f))); | ||
| 8497 | UNBLOCK_INPUT; | ||
| 8498 | } | ||
| 8435 | 8499 | ||
| 8436 | if (!img->pixmap) | 8500 | if (!img->pixmap) |
| 8437 | { | 8501 | { |