summaryrefslogtreecommitdiff
path: root/src/modules/evas/image_loaders/psd/evas_image_load_psd.c
diff options
context:
space:
mode:
authorCarsten Haitzler (Rasterman) <raster@rasterman.com>2020-09-19 22:32:57 +0100
committerCarsten Haitzler (Rasterman) <raster@rasterman.com>2020-09-19 22:32:57 +0100
commite243a60bb2f77c3156e4505619895863c4f1c1ff (patch)
treeb832dfc7bdf1efcfe0c4d887015cfc0dee20ede0 /src/modules/evas/image_loaders/psd/evas_image_load_psd.c
parentf3fdcf56923c8a2ca126e14d915e6386c7c4ff7e (diff)
evas - psd loader - check read values to try make coverity happy
this is trying to fix CID 1402688, 1402687, 1402682, 1402665. not sure it will or will not but it does dot i's and cross t's
Diffstat (limited to '')
-rw-r--r--src/modules/evas/image_loaders/psd/evas_image_load_psd.c38
1 files changed, 27 insertions, 11 deletions
diff --git a/src/modules/evas/image_loaders/psd/evas_image_load_psd.c b/src/modules/evas/image_loaders/psd/evas_image_load_psd.c
index 5dcf31039b..58cd961acf 100644
--- a/src/modules/evas/image_loaders/psd/evas_image_load_psd.c
+++ b/src/modules/evas/image_loaders/psd/evas_image_load_psd.c
@@ -61,7 +61,7 @@ static Eina_Bool get_compressed_channels_length(PSD_Header *Head,
61static int 61static int
62read_ushort(const unsigned char *map, size_t length, size_t *position, unsigned short *ret) 62read_ushort(const unsigned char *map, size_t length, size_t *position, unsigned short *ret)
63{ 63{
64 if (*position + 2 > length) return 0; 64 if (((*position) + 2) > length) return 0;
65 // FIXME: need to check order 65 // FIXME: need to check order
66 *ret = (map[(*position) + 0] << 8) | map[(*position) + 1]; 66 *ret = (map[(*position) + 0] << 8) | map[(*position) + 1];
67 *position += 2; 67 *position += 2;
@@ -71,7 +71,7 @@ read_ushort(const unsigned char *map, size_t length, size_t *position, unsigned
71static int 71static int
72read_uint(const unsigned char *map, size_t length, size_t *position, unsigned int *ret) 72read_uint(const unsigned char *map, size_t length, size_t *position, unsigned int *ret)
73{ 73{
74 if (*position + 4 > length) return 0; 74 if (((*position) + 4) > length) return 0;
75 // FIXME: need to check order 75 // FIXME: need to check order
76 *ret = ARGB_JOIN(map[(*position) + 0], map[(*position) + 1], map[(*position) + 2], map[(*position) + 3]); 76 *ret = ARGB_JOIN(map[(*position) + 0], map[(*position) + 1], map[(*position) + 2], map[(*position) + 3]);
77 *position += 4; 77 *position += 4;
@@ -81,14 +81,14 @@ read_uint(const unsigned char *map, size_t length, size_t *position, unsigned in
81static int 81static int
82read_block(const unsigned char *map, size_t length, size_t *position, void *target, size_t size) 82read_block(const unsigned char *map, size_t length, size_t *position, void *target, size_t size)
83{ 83{
84 if (*position + size > length) return 0; 84 if (((*position) + size) > length) return 0;
85 memcpy(target, map + *position, size); 85 memcpy(target, map + *position, size);
86 *position += size; 86 *position += size;
87 return 1; 87 return 1;
88} 88}
89 89
90// Internal function used to get the Psd header from the current file. 90// Internal function used to get the Psd header from the current file.
91Eina_Bool 91static Eina_Bool
92psd_get_header(PSD_Header *header, const unsigned char *map, size_t length, size_t *position) 92psd_get_header(PSD_Header *header, const unsigned char *map, size_t length, size_t *position)
93{ 93{
94 unsigned short tmp; 94 unsigned short tmp;
@@ -114,7 +114,7 @@ psd_get_header(PSD_Header *header, const unsigned char *map, size_t length, size
114 114
115 115
116// Internal function used to check if the HEADER is a valid Psd header. 116// Internal function used to check if the HEADER is a valid Psd header.
117Eina_Bool 117static Eina_Bool
118is_psd(PSD_Header *header) 118is_psd(PSD_Header *header)
119{ 119{
120 if (strncmp((char*)header->signature, "8BPS", 4)) 120 if (strncmp((char*)header->signature, "8BPS", 4))
@@ -238,7 +238,7 @@ read_compressed_channel(const unsigned char *map, size_t length, size_t *positio
238} 238}
239 239
240 240
241Eina_Bool 241static Eina_Bool
242psd_get_data(PSD_Header *head, 242psd_get_data(PSD_Header *head,
243 const unsigned char *map, size_t length, size_t *position, 243 const unsigned char *map, size_t length, size_t *position,
244 unsigned char *buffer, Eina_Bool compressed, 244 unsigned char *buffer, Eina_Bool compressed,
@@ -492,7 +492,7 @@ psd_get_data(PSD_Header *head,
492} 492}
493 493
494 494
495Eina_Bool 495static Eina_Bool
496get_single_channel(PSD_Header *head, 496get_single_channel(PSD_Header *head,
497 const unsigned char *map, size_t length, size_t *position, 497 const unsigned char *map, size_t length, size_t *position,
498 unsigned char *buffer, 498 unsigned char *buffer,
@@ -552,7 +552,7 @@ get_single_channel(PSD_Header *head,
552 return EINA_TRUE; 552 return EINA_TRUE;
553} 553}
554 554
555Eina_Bool 555static Eina_Bool
556read_psd_grey(void *pixels, PSD_Header *head, const unsigned char *map, size_t length, size_t *position, int *error) 556read_psd_grey(void *pixels, PSD_Header *head, const unsigned char *map, size_t length, size_t *position, int *error)
557{ 557{
558 unsigned int color_mode, resource_size, misc_info; 558 unsigned int color_mode, resource_size, misc_info;
@@ -566,15 +566,19 @@ read_psd_grey(void *pixels, PSD_Header *head, const unsigned char *map, size_t l
566 CHECK_RET(read_uint(map, length, position, &color_mode)); 566 CHECK_RET(read_uint(map, length, position, &color_mode));
567 // Skip over the 'color mode data section' 567 // Skip over the 'color mode data section'
568 *position += color_mode; 568 *position += color_mode;
569 if ((*position) >= length) return EINA_FALSE;
569 570
570 CHECK_RET(read_uint(map, length, position, &resource_size)); 571 CHECK_RET(read_uint(map, length, position, &resource_size));
571 // Read the 'image resources section' 572 // Read the 'image resources section'
572 *position += resource_size; 573 *position += resource_size;
574 if ((*position) >= length) return EINA_FALSE;
573 575
574 CHECK_RET(read_uint(map, length, position, &misc_info)); 576 CHECK_RET(read_uint(map, length, position, &misc_info));
575 *position += misc_info; 577 *position += misc_info;
578 if ((*position) >= length) return EINA_FALSE;
576 579
577 CHECK_RET(read_ushort(map, length, position, &compressed)); 580 CHECK_RET(read_ushort(map, length, position, &compressed));
581 if (compressed != 0) compressed = EINA_TRUE;
578 582
579 head->channel_num = head->channels; 583 head->channel_num = head->channels;
580 // Temporary to read only one channel...some greyscale .psd files have 2. 584 // Temporary to read only one channel...some greyscale .psd files have 2.
@@ -602,7 +606,7 @@ read_psd_grey(void *pixels, PSD_Header *head, const unsigned char *map, size_t l
602} 606}
603 607
604 608
605Eina_Bool 609static Eina_Bool
606read_psd_indexed(void *pixels, PSD_Header *head, const unsigned char *map, size_t length, size_t *position, int *error) 610read_psd_indexed(void *pixels, PSD_Header *head, const unsigned char *map, size_t length, size_t *position, int *error)
607{ 611{
608 unsigned int color_mode, resource_size, misc_info; 612 unsigned int color_mode, resource_size, misc_info;
@@ -624,15 +628,19 @@ read_psd_indexed(void *pixels, PSD_Header *head, const unsigned char *map, size_
624 */ 628 */
625 // Skip over the 'color mode data section' 629 // Skip over the 'color mode data section'
626 *position += color_mode; 630 *position += color_mode;
631 if ((*position) >= length) return EINA_FALSE;
627 632
628 // Read the 'image resources section' 633 // Read the 'image resources section'
629 CHECK_RET(read_uint(map, length, position, &resource_size)); 634 CHECK_RET(read_uint(map, length, position, &resource_size));
630 *position += resource_size; 635 *position += resource_size;
636 if ((*position) >= length) return EINA_FALSE;
631 637
632 CHECK_RET(read_uint(map, length, position, &misc_info)); 638 CHECK_RET(read_uint(map, length, position, &misc_info));
633 *position += misc_info; 639 *position += misc_info;
640 if ((*position) >= length) return EINA_FALSE;
634 641
635 CHECK_RET(read_ushort(map, length, position, &compressed)); 642 CHECK_RET(read_ushort(map, length, position, &compressed));
643 if (compressed != 0) compressed = EINA_TRUE;
636 644
637 if (head->channels != 1 || head->depth != 8) 645 if (head->channels != 1 || head->depth != 8)
638 { 646 {
@@ -648,7 +656,7 @@ read_psd_indexed(void *pixels, PSD_Header *head, const unsigned char *map, size_
648#undef CHECK_RET 656#undef CHECK_RET
649} 657}
650 658
651Eina_Bool 659static Eina_Bool
652read_psd_rgb(void *pixels, PSD_Header *head, const unsigned char *map, size_t length, size_t *position, int *error) 660read_psd_rgb(void *pixels, PSD_Header *head, const unsigned char *map, size_t length, size_t *position, int *error)
653{ 661{
654 unsigned int color_mode, resource_size, misc_info; 662 unsigned int color_mode, resource_size, misc_info;
@@ -660,15 +668,19 @@ read_psd_rgb(void *pixels, PSD_Header *head, const unsigned char *map, size_t le
660 CHECK_RET(read_uint(map, length, position, &color_mode)); 668 CHECK_RET(read_uint(map, length, position, &color_mode));
661 // Skip over the 'color mode data section' 669 // Skip over the 'color mode data section'
662 *position += color_mode; 670 *position += color_mode;
671 if ((*position) >= length) return EINA_FALSE;
663 672
664 // Read the 'image resources section' 673 // Read the 'image resources section'
665 CHECK_RET(read_uint(map, length, position, &resource_size)); 674 CHECK_RET(read_uint(map, length, position, &resource_size));
666 *position += resource_size; 675 *position += resource_size;
676 if ((*position) >= length) return EINA_FALSE;
667 677
668 CHECK_RET(read_uint(map, length, position, &misc_info)); 678 CHECK_RET(read_uint(map, length, position, &misc_info));
669 *position += misc_info; 679 *position += misc_info;
680 if ((*position) >= length) return EINA_FALSE;
670 681
671 CHECK_RET(read_ushort(map, length, position, &compressed)); 682 CHECK_RET(read_ushort(map, length, position, &compressed));
683 if (compressed != 0) compressed = EINA_TRUE;
672 684
673 head->channel_num = head->channels; 685 head->channel_num = head->channels;
674 686
@@ -690,7 +702,7 @@ read_psd_rgb(void *pixels, PSD_Header *head, const unsigned char *map, size_t le
690#undef CHECK_RET 702#undef CHECK_RET
691} 703}
692 704
693Eina_Bool 705static Eina_Bool
694read_psd_cmyk(Emile_Image_Property *prop, void *pixels, PSD_Header *head, const unsigned char *map, size_t length, size_t *position, int *error) 706read_psd_cmyk(Emile_Image_Property *prop, void *pixels, PSD_Header *head, const unsigned char *map, size_t length, size_t *position, int *error)
695{ 707{
696 unsigned int color_mode, resource_size, misc_info, size, j, data_size; 708 unsigned int color_mode, resource_size, misc_info, size, j, data_size;
@@ -707,15 +719,19 @@ read_psd_cmyk(Emile_Image_Property *prop, void *pixels, PSD_Header *head, const
707 CHECK_RET(read_uint(map, length, position, &color_mode)); 719 CHECK_RET(read_uint(map, length, position, &color_mode));
708 // Skip over the 'color mode data section' 720 // Skip over the 'color mode data section'
709 *position += color_mode; 721 *position += color_mode;
722 if ((*position) >= length) return EINA_FALSE;
710 723
711 CHECK_RET(read_uint(map, length, position, &resource_size)); 724 CHECK_RET(read_uint(map, length, position, &resource_size));
712 // Read the 'image resources section' 725 // Read the 'image resources section'
713 *position += resource_size; 726 *position += resource_size;
727 if ((*position) >= length) return EINA_FALSE;
714 728
715 CHECK_RET(read_uint(map, length, position, &misc_info)); 729 CHECK_RET(read_uint(map, length, position, &misc_info));
716 *position += misc_info; 730 *position += misc_info;
731 if ((*position) >= length) return EINA_FALSE;
717 732
718 CHECK_RET(read_ushort(map, length, position, &compressed)); 733 CHECK_RET(read_ushort(map, length, position, &compressed));
734 if (compressed != 0) compressed = EINA_TRUE;
719 735
720 switch (head->channels) 736 switch (head->channels)
721 { 737 {