diff options
| author | Paul Eggert | 2011-06-22 09:15:41 -0700 |
|---|---|---|
| committer | Paul Eggert | 2011-06-22 09:15:41 -0700 |
| commit | 31fd4b3280acee4030efde84a0e23ae2b006ee31 (patch) | |
| tree | 0b2245daf7e6f772cbaabf8916faeb34683bb390 /src/image.c | |
| parent | ddb7ffeeb8ace6501eb453f50f0f9f6852eda21f (diff) | |
| parent | 510005210ac9f4d813c4a2cc99b2c3c11e57c055 (diff) | |
| download | emacs-31fd4b3280acee4030efde84a0e23ae2b006ee31.tar.gz emacs-31fd4b3280acee4030efde84a0e23ae2b006ee31.zip | |
Merge: Integer overflow and signedness fixes (Bug#8873).
A few related buffer overrun fixes, too.
Diffstat (limited to 'src/image.c')
| -rw-r--r-- | src/image.c | 57 |
1 files changed, 26 insertions, 31 deletions
diff --git a/src/image.c b/src/image.c index 802568101ea..a9785e5d00f 100644 --- a/src/image.c +++ b/src/image.c | |||
| @@ -182,20 +182,20 @@ XPutPixel (XImagePtr ximage, int x, int y, unsigned long pixel) | |||
| 182 | /* Functions to access the contents of a bitmap, given an id. */ | 182 | /* Functions to access the contents of a bitmap, given an id. */ |
| 183 | 183 | ||
| 184 | int | 184 | int |
| 185 | x_bitmap_height (FRAME_PTR f, int id) | 185 | x_bitmap_height (FRAME_PTR f, ptrdiff_t id) |
| 186 | { | 186 | { |
| 187 | return FRAME_X_DISPLAY_INFO (f)->bitmaps[id - 1].height; | 187 | return FRAME_X_DISPLAY_INFO (f)->bitmaps[id - 1].height; |
| 188 | } | 188 | } |
| 189 | 189 | ||
| 190 | int | 190 | int |
| 191 | x_bitmap_width (FRAME_PTR f, int id) | 191 | x_bitmap_width (FRAME_PTR f, ptrdiff_t id) |
| 192 | { | 192 | { |
| 193 | return FRAME_X_DISPLAY_INFO (f)->bitmaps[id - 1].width; | 193 | return FRAME_X_DISPLAY_INFO (f)->bitmaps[id - 1].width; |
| 194 | } | 194 | } |
| 195 | 195 | ||
| 196 | #if defined (HAVE_X_WINDOWS) || defined (HAVE_NTGUI) | 196 | #if defined (HAVE_X_WINDOWS) || defined (HAVE_NTGUI) |
| 197 | int | 197 | int |
| 198 | x_bitmap_pixmap (FRAME_PTR f, int id) | 198 | x_bitmap_pixmap (FRAME_PTR f, ptrdiff_t id) |
| 199 | { | 199 | { |
| 200 | return (int) FRAME_X_DISPLAY_INFO (f)->bitmaps[id - 1].pixmap; | 200 | return (int) FRAME_X_DISPLAY_INFO (f)->bitmaps[id - 1].pixmap; |
| 201 | } | 201 | } |
| @@ -203,7 +203,7 @@ x_bitmap_pixmap (FRAME_PTR f, int id) | |||
| 203 | 203 | ||
| 204 | #ifdef HAVE_X_WINDOWS | 204 | #ifdef HAVE_X_WINDOWS |
| 205 | int | 205 | int |
| 206 | x_bitmap_mask (FRAME_PTR f, int id) | 206 | x_bitmap_mask (FRAME_PTR f, ptrdiff_t id) |
| 207 | { | 207 | { |
| 208 | return FRAME_X_DISPLAY_INFO (f)->bitmaps[id - 1].mask; | 208 | return FRAME_X_DISPLAY_INFO (f)->bitmaps[id - 1].mask; |
| 209 | } | 209 | } |
| @@ -211,11 +211,11 @@ x_bitmap_mask (FRAME_PTR f, int id) | |||
| 211 | 211 | ||
| 212 | /* Allocate a new bitmap record. Returns index of new record. */ | 212 | /* Allocate a new bitmap record. Returns index of new record. */ |
| 213 | 213 | ||
| 214 | static int | 214 | static ptrdiff_t |
| 215 | x_allocate_bitmap_record (FRAME_PTR f) | 215 | x_allocate_bitmap_record (FRAME_PTR f) |
| 216 | { | 216 | { |
| 217 | Display_Info *dpyinfo = FRAME_X_DISPLAY_INFO (f); | 217 | Display_Info *dpyinfo = FRAME_X_DISPLAY_INFO (f); |
| 218 | int i; | 218 | ptrdiff_t i; |
| 219 | 219 | ||
| 220 | if (dpyinfo->bitmaps == NULL) | 220 | if (dpyinfo->bitmaps == NULL) |
| 221 | { | 221 | { |
| @@ -233,6 +233,9 @@ x_allocate_bitmap_record (FRAME_PTR f) | |||
| 233 | if (dpyinfo->bitmaps[i].refcount == 0) | 233 | if (dpyinfo->bitmaps[i].refcount == 0) |
| 234 | return i + 1; | 234 | return i + 1; |
| 235 | 235 | ||
| 236 | if (min (PTRDIFF_MAX, SIZE_MAX) / sizeof (Bitmap_Record) / 2 | ||
| 237 | < dpyinfo->bitmaps_size) | ||
| 238 | memory_full (SIZE_MAX); | ||
| 236 | dpyinfo->bitmaps_size *= 2; | 239 | dpyinfo->bitmaps_size *= 2; |
| 237 | dpyinfo->bitmaps | 240 | dpyinfo->bitmaps |
| 238 | = (Bitmap_Record *) xrealloc (dpyinfo->bitmaps, | 241 | = (Bitmap_Record *) xrealloc (dpyinfo->bitmaps, |
| @@ -250,11 +253,11 @@ x_reference_bitmap (FRAME_PTR f, int id) | |||
| 250 | 253 | ||
| 251 | /* Create a bitmap for frame F from a HEIGHT x WIDTH array of bits at BITS. */ | 254 | /* Create a bitmap for frame F from a HEIGHT x WIDTH array of bits at BITS. */ |
| 252 | 255 | ||
| 253 | int | 256 | ptrdiff_t |
| 254 | x_create_bitmap_from_data (struct frame *f, char *bits, unsigned int width, unsigned int height) | 257 | x_create_bitmap_from_data (struct frame *f, char *bits, unsigned int width, unsigned int height) |
| 255 | { | 258 | { |
| 256 | Display_Info *dpyinfo = FRAME_X_DISPLAY_INFO (f); | 259 | Display_Info *dpyinfo = FRAME_X_DISPLAY_INFO (f); |
| 257 | int id; | 260 | ptrdiff_t id; |
| 258 | 261 | ||
| 259 | #ifdef HAVE_X_WINDOWS | 262 | #ifdef HAVE_X_WINDOWS |
| 260 | Pixmap bitmap; | 263 | Pixmap bitmap; |
| @@ -309,7 +312,7 @@ x_create_bitmap_from_data (struct frame *f, char *bits, unsigned int width, unsi | |||
| 309 | 312 | ||
| 310 | /* Create bitmap from file FILE for frame F. */ | 313 | /* Create bitmap from file FILE for frame F. */ |
| 311 | 314 | ||
| 312 | int | 315 | ptrdiff_t |
| 313 | x_create_bitmap_from_file (struct frame *f, Lisp_Object file) | 316 | x_create_bitmap_from_file (struct frame *f, Lisp_Object file) |
| 314 | { | 317 | { |
| 315 | Display_Info *dpyinfo = FRAME_X_DISPLAY_INFO (f); | 318 | Display_Info *dpyinfo = FRAME_X_DISPLAY_INFO (f); |
| @@ -319,7 +322,7 @@ x_create_bitmap_from_file (struct frame *f, Lisp_Object file) | |||
| 319 | #endif /* HAVE_NTGUI */ | 322 | #endif /* HAVE_NTGUI */ |
| 320 | 323 | ||
| 321 | #ifdef HAVE_NS | 324 | #ifdef HAVE_NS |
| 322 | int id; | 325 | ptrdiff_t id; |
| 323 | void *bitmap = ns_image_from_file (file); | 326 | void *bitmap = ns_image_from_file (file); |
| 324 | 327 | ||
| 325 | if (!bitmap) | 328 | if (!bitmap) |
| @@ -340,7 +343,8 @@ x_create_bitmap_from_file (struct frame *f, Lisp_Object file) | |||
| 340 | #ifdef HAVE_X_WINDOWS | 343 | #ifdef HAVE_X_WINDOWS |
| 341 | unsigned int width, height; | 344 | unsigned int width, height; |
| 342 | Pixmap bitmap; | 345 | Pixmap bitmap; |
| 343 | int xhot, yhot, result, id; | 346 | int xhot, yhot, result; |
| 347 | ptrdiff_t id; | ||
| 344 | Lisp_Object found; | 348 | Lisp_Object found; |
| 345 | int fd; | 349 | int fd; |
| 346 | char *filename; | 350 | char *filename; |
| @@ -413,7 +417,7 @@ free_bitmap_record (Display_Info *dpyinfo, Bitmap_Record *bm) | |||
| 413 | /* Remove reference to bitmap with id number ID. */ | 417 | /* Remove reference to bitmap with id number ID. */ |
| 414 | 418 | ||
| 415 | void | 419 | void |
| 416 | x_destroy_bitmap (FRAME_PTR f, int id) | 420 | x_destroy_bitmap (FRAME_PTR f, ptrdiff_t id) |
| 417 | { | 421 | { |
| 418 | Display_Info *dpyinfo = FRAME_X_DISPLAY_INFO (f); | 422 | Display_Info *dpyinfo = FRAME_X_DISPLAY_INFO (f); |
| 419 | 423 | ||
| @@ -435,7 +439,7 @@ x_destroy_bitmap (FRAME_PTR f, int id) | |||
| 435 | void | 439 | void |
| 436 | x_destroy_all_bitmaps (Display_Info *dpyinfo) | 440 | x_destroy_all_bitmaps (Display_Info *dpyinfo) |
| 437 | { | 441 | { |
| 438 | int i; | 442 | ptrdiff_t i; |
| 439 | Bitmap_Record *bm = dpyinfo->bitmaps; | 443 | Bitmap_Record *bm = dpyinfo->bitmaps; |
| 440 | 444 | ||
| 441 | for (i = 0; i < dpyinfo->bitmaps_last; i++, bm++) | 445 | for (i = 0; i < dpyinfo->bitmaps_last; i++, bm++) |
| @@ -467,7 +471,7 @@ static void x_destroy_x_image (XImagePtr ximg); | |||
| 467 | It's nicer with some borders in this context */ | 471 | It's nicer with some borders in this context */ |
| 468 | 472 | ||
| 469 | int | 473 | int |
| 470 | x_create_bitmap_mask (struct frame *f, int id) | 474 | x_create_bitmap_mask (struct frame *f, ptrdiff_t id) |
| 471 | { | 475 | { |
| 472 | Pixmap pixmap, mask; | 476 | Pixmap pixmap, mask; |
| 473 | XImagePtr ximg, mask_img; | 477 | XImagePtr ximg, mask_img; |
| @@ -2308,7 +2312,7 @@ xbm_image_p (Lisp_Object object) | |||
| 2308 | else | 2312 | else |
| 2309 | { | 2313 | { |
| 2310 | Lisp_Object data; | 2314 | Lisp_Object data; |
| 2311 | int width, height; | 2315 | EMACS_INT width, height; |
| 2312 | 2316 | ||
| 2313 | /* Entries for `:width', `:height' and `:data' must be present. */ | 2317 | /* Entries for `:width', `:height' and `:data' must be present. */ |
| 2314 | if (!kw[XBM_WIDTH].count | 2318 | if (!kw[XBM_WIDTH].count |
| @@ -2324,7 +2328,7 @@ xbm_image_p (Lisp_Object object) | |||
| 2324 | data. */ | 2328 | data. */ |
| 2325 | if (VECTORP (data)) | 2329 | if (VECTORP (data)) |
| 2326 | { | 2330 | { |
| 2327 | int i; | 2331 | EMACS_INT i; |
| 2328 | 2332 | ||
| 2329 | /* Number of elements of the vector must be >= height. */ | 2333 | /* Number of elements of the vector must be >= height. */ |
| 2330 | if (ASIZE (data) < height) | 2334 | if (ASIZE (data) < height) |
| @@ -3282,11 +3286,12 @@ xpm_image_p (Lisp_Object object) | |||
| 3282 | #endif /* HAVE_XPM || HAVE_NS */ | 3286 | #endif /* HAVE_XPM || HAVE_NS */ |
| 3283 | 3287 | ||
| 3284 | #if defined HAVE_XPM && defined HAVE_X_WINDOWS && !defined USE_GTK | 3288 | #if defined HAVE_XPM && defined HAVE_X_WINDOWS && !defined USE_GTK |
| 3285 | int | 3289 | ptrdiff_t |
| 3286 | x_create_bitmap_from_xpm_data (struct frame *f, const char **bits) | 3290 | x_create_bitmap_from_xpm_data (struct frame *f, const char **bits) |
| 3287 | { | 3291 | { |
| 3288 | Display_Info *dpyinfo = FRAME_X_DISPLAY_INFO (f); | 3292 | Display_Info *dpyinfo = FRAME_X_DISPLAY_INFO (f); |
| 3289 | int id, rc; | 3293 | ptrdiff_t id; |
| 3294 | int rc; | ||
| 3290 | XpmAttributes attrs; | 3295 | XpmAttributes attrs; |
| 3291 | Pixmap bitmap, mask; | 3296 | Pixmap bitmap, mask; |
| 3292 | 3297 | ||
| @@ -3590,25 +3595,14 @@ xpm_load (struct frame *f, struct image *img) | |||
| 3590 | /* XPM support functions for NS where libxpm is not available. | 3595 | /* XPM support functions for NS where libxpm is not available. |
| 3591 | Only XPM version 3 (without any extensions) is supported. */ | 3596 | Only XPM version 3 (without any extensions) is supported. */ |
| 3592 | 3597 | ||
| 3593 | static int xpm_scan (const unsigned char **, const unsigned char *, | ||
| 3594 | const unsigned char **, int *); | ||
| 3595 | static Lisp_Object xpm_make_color_table_v | ||
| 3596 | (void (**) (Lisp_Object, const unsigned char *, int, Lisp_Object), | ||
| 3597 | Lisp_Object (**) (Lisp_Object, const unsigned char *, int)); | ||
| 3598 | static void xpm_put_color_table_v (Lisp_Object, const unsigned char *, | 3598 | static void xpm_put_color_table_v (Lisp_Object, const unsigned char *, |
| 3599 | int, Lisp_Object); | 3599 | int, Lisp_Object); |
| 3600 | static Lisp_Object xpm_get_color_table_v (Lisp_Object, | 3600 | static Lisp_Object xpm_get_color_table_v (Lisp_Object, |
| 3601 | const unsigned char *, int); | 3601 | const unsigned char *, int); |
| 3602 | static Lisp_Object xpm_make_color_table_h | ||
| 3603 | (void (**) (Lisp_Object, const unsigned char *, int, Lisp_Object), | ||
| 3604 | Lisp_Object (**) (Lisp_Object, const unsigned char *, int)); | ||
| 3605 | static void xpm_put_color_table_h (Lisp_Object, const unsigned char *, | 3602 | static void xpm_put_color_table_h (Lisp_Object, const unsigned char *, |
| 3606 | int, Lisp_Object); | 3603 | int, Lisp_Object); |
| 3607 | static Lisp_Object xpm_get_color_table_h (Lisp_Object, | 3604 | static Lisp_Object xpm_get_color_table_h (Lisp_Object, |
| 3608 | const unsigned char *, int); | 3605 | const unsigned char *, int); |
| 3609 | static int xpm_str_to_color_key (const char *); | ||
| 3610 | static int xpm_load_image (struct frame *, struct image *, | ||
| 3611 | const unsigned char *, const unsigned char *); | ||
| 3612 | 3606 | ||
| 3613 | /* Tokens returned from xpm_scan. */ | 3607 | /* Tokens returned from xpm_scan. */ |
| 3614 | 3608 | ||
| @@ -3630,7 +3624,7 @@ static int | |||
| 3630 | xpm_scan (const unsigned char **s, | 3624 | xpm_scan (const unsigned char **s, |
| 3631 | const unsigned char *end, | 3625 | const unsigned char *end, |
| 3632 | const unsigned char **beg, | 3626 | const unsigned char **beg, |
| 3633 | int *len) | 3627 | ptrdiff_t *len) |
| 3634 | { | 3628 | { |
| 3635 | int c; | 3629 | int c; |
| 3636 | 3630 | ||
| @@ -3800,7 +3794,8 @@ xpm_load_image (struct frame *f, | |||
| 3800 | unsigned char buffer[BUFSIZ]; | 3794 | unsigned char buffer[BUFSIZ]; |
| 3801 | int width, height, x, y; | 3795 | int width, height, x, y; |
| 3802 | int num_colors, chars_per_pixel; | 3796 | int num_colors, chars_per_pixel; |
| 3803 | int len, LA1; | 3797 | ptrdiff_t len; |
| 3798 | int LA1; | ||
| 3804 | void (*put_color_table) (Lisp_Object, const unsigned char *, int, Lisp_Object); | 3799 | void (*put_color_table) (Lisp_Object, const unsigned char *, int, Lisp_Object); |
| 3805 | Lisp_Object (*get_color_table) (Lisp_Object, const unsigned char *, int); | 3800 | Lisp_Object (*get_color_table) (Lisp_Object, const unsigned char *, int); |
| 3806 | Lisp_Object frame, color_symbols, color_table; | 3801 | Lisp_Object frame, color_symbols, color_table; |