aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJason Rumney2008-03-28 14:59:22 +0000
committerJason Rumney2008-03-28 14:59:22 +0000
commitb9c89e11fbf44c471b60cd385d770597aea7c653 (patch)
treeb8333df1ba136f1a2003be9d8644b5005bccab01 /src
parent3ae8f8760f33ffd2c25f564214c9f1f5fd34c1a3 (diff)
downloademacs-b9c89e11fbf44c471b60cd385d770597aea7c653.tar.gz
emacs-b9c89e11fbf44c471b60cd385d770597aea7c653.zip
(pbm_load): Allow color values up to 65535.
Throw an error if max_color_idx is outside the supported range. Report an error when image size is invalid. Read two bytes at a time when raw images have max_color_idx above 255.
Diffstat (limited to 'src')
-rw-r--r--src/ChangeLog7
-rw-r--r--src/image.c42
2 files changed, 38 insertions, 11 deletions
diff --git a/src/ChangeLog b/src/ChangeLog
index d54ad87e772..b0a940292e5 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,3 +1,10 @@
12008-03-28 Jason Rumney <jasonr@gnu.org>
2
3 * image.c (pbm_load): Allow color values up to 65535.
4 Throw an error if max_color_idx is outside the supported range.
5 Report an error when image size is invalid.
6 Read two bytes at a time when raw images have max_color_idx above 255.
7
12008-03-26 Alexandre Oliva <aoliva@redhat.com> (tiny change) 82008-03-26 Alexandre Oliva <aoliva@redhat.com> (tiny change)
2 9
3 * regex.c (EXTEND_BUFFER): Change order of pointer addition 10 * regex.c (EXTEND_BUFFER): Change order of pointer addition
diff --git a/src/image.c b/src/image.c
index 71a8c4b4995..16515852642 100644
--- a/src/image.c
+++ b/src/image.c
@@ -5776,13 +5776,18 @@ pbm_load (f, img)
5776 if (type != PBM_MONO) 5776 if (type != PBM_MONO)
5777 { 5777 {
5778 max_color_idx = pbm_scan_number (&p, end); 5778 max_color_idx = pbm_scan_number (&p, end);
5779 if (raw_p && max_color_idx > 255) 5779 if (max_color_idx > 65535 || max_color_idx < 0)
5780 max_color_idx = 255; 5780 {
5781 image_error ("Unsupported maximum PBM color value", Qnil, Qnil);
5782 goto error;
5783 }
5781 } 5784 }
5782 5785
5783 if (!check_image_size (f, width, height) 5786 if (!check_image_size (f, width, height))
5784 || (type != PBM_MONO && max_color_idx < 0)) 5787 {
5785 goto error; 5788 image_error ("Invalid image size", Qnil, Qnil);
5789 goto error;
5790 }
5786 5791
5787 if (!x_create_x_image_and_pixmap (f, width, height, 0, 5792 if (!x_create_x_image_and_pixmap (f, width, height, 0,
5788 &ximg, &img->pixmap)) 5793 &ximg, &img->pixmap))
@@ -5842,10 +5847,13 @@ pbm_load (f, img)
5842 } 5847 }
5843 else 5848 else
5844 { 5849 {
5845 if (raw_p 5850 int expected_size = height * width;
5846 && ((type == PBM_GRAY) 5851 if (max_color_idx > 255)
5847 ? (p + height * width > end) 5852 expected_size *= 2;
5848 : (p + 3 * height * width > end))) 5853 if (type == PBM_COLOR)
5854 expected_size *= 3;
5855
5856 if (raw_p && p + expected_size > end)
5849 { 5857 {
5850 x_destroy_x_image (ximg); 5858 x_destroy_x_image (ximg);
5851 x_clear_image (f, img); 5859 x_clear_image (f, img);
@@ -5859,13 +5867,25 @@ pbm_load (f, img)
5859 { 5867 {
5860 int r, g, b; 5868 int r, g, b;
5861 5869
5862 if (type == PBM_GRAY) 5870 if (type == PBM_GRAY && raw_p)
5863 r = g = b = raw_p ? *p++ : pbm_scan_number (&p, end); 5871 {
5872 r = g = b = *p++;
5873 if (max_color_idx > 255)
5874 r = g = b = r * 256 + *p++;
5875 }
5876 else if (type == PBM_GRAY)
5877 r = g = b = pbm_scan_number (&p, end);
5864 else if (raw_p) 5878 else if (raw_p)
5865 { 5879 {
5866 r = *p++; 5880 r = *p++;
5881 if (max_color_idx > 255)
5882 r = r * 256 + *p++;
5867 g = *p++; 5883 g = *p++;
5884 if (max_color_idx > 255)
5885 g = g * 256 + *p++;
5868 b = *p++; 5886 b = *p++;
5887 if (max_color_idx > 255)
5888 b = b * 256 + *p++;
5869 } 5889 }
5870 else 5890 else
5871 { 5891 {