aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/linden/indra/llimage/llimagetga.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'linden/indra/llimage/llimagetga.cpp')
-rw-r--r--linden/indra/llimage/llimagetga.cpp50
1 files changed, 50 insertions, 0 deletions
diff --git a/linden/indra/llimage/llimagetga.cpp b/linden/indra/llimage/llimagetga.cpp
index 39da50a..805297f 100644
--- a/linden/indra/llimage/llimagetga.cpp
+++ b/linden/indra/llimage/llimagetga.cpp
@@ -1,6 +1,8 @@
1/** 1/**
2 * @file llimagetga.cpp 2 * @file llimagetga.cpp
3 * 3 *
4 * $LicenseInfo:firstyear=2001&license=viewergpl$
5 *
4 * Copyright (c) 2001-2007, Linden Research, Inc. 6 * Copyright (c) 2001-2007, Linden Research, Inc.
5 * 7 *
6 * Second Life Viewer Source Code 8 * Second Life Viewer Source Code
@@ -23,6 +25,7 @@
23 * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO 25 * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
24 * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY, 26 * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
25 * COMPLETENESS OR PERFORMANCE. 27 * COMPLETENESS OR PERFORMANCE.
28 * $/LicenseInfo$
26 */ 29 */
27 30
28#include "linden_common.h" 31#include "linden_common.h"
@@ -747,6 +750,7 @@ BOOL LLImageTGA::decodeTruecolorRle32( LLImageRaw* raw_image, BOOL &alpha_opaque
747 U32* dst_pixels = (U32*) dst; 750 U32* dst_pixels = (U32*) dst;
748 751
749 U8* src = getData() + mDataOffset; 752 U8* src = getData() + mDataOffset;
753 U8* last_src = src + getDataSize();
750 754
751 U32 rgba; 755 U32 rgba;
752 U8* rgba_byte_p = (U8*) &rgba; 756 U8* rgba_byte_p = (U8*) &rgba;
@@ -755,6 +759,10 @@ BOOL LLImageTGA::decodeTruecolorRle32( LLImageRaw* raw_image, BOOL &alpha_opaque
755 while( dst_pixels <= last_dst_pixel ) 759 while( dst_pixels <= last_dst_pixel )
756 { 760 {
757 // Read RLE block header 761 // Read RLE block header
762
763 if (src >= last_src)
764 return FALSE;
765
758 U8 block_header_byte = *src; 766 U8 block_header_byte = *src;
759 src++; 767 src++;
760 768
@@ -762,6 +770,10 @@ BOOL LLImageTGA::decodeTruecolorRle32( LLImageRaw* raw_image, BOOL &alpha_opaque
762 if( block_header_byte & 0x80 ) 770 if( block_header_byte & 0x80 )
763 { 771 {
764 // Encoded (duplicate-pixel) block 772 // Encoded (duplicate-pixel) block
773
774 if (src + 3 >= last_src)
775 return FALSE;
776
765 rgba_byte_p[0] = src[2]; 777 rgba_byte_p[0] = src[2];
766 rgba_byte_p[1] = src[1]; 778 rgba_byte_p[1] = src[1];
767 rgba_byte_p[2] = src[0]; 779 rgba_byte_p[2] = src[0];
@@ -786,6 +798,9 @@ BOOL LLImageTGA::decodeTruecolorRle32( LLImageRaw* raw_image, BOOL &alpha_opaque
786 // Unencoded block 798 // Unencoded block
787 do 799 do
788 { 800 {
801 if (src + 3 >= last_src)
802 return FALSE;
803
789 ((U8*)dst_pixels)[0] = src[2]; 804 ((U8*)dst_pixels)[0] = src[2];
790 ((U8*)dst_pixels)[1] = src[1]; 805 ((U8*)dst_pixels)[1] = src[1];
791 ((U8*)dst_pixels)[2] = src[0]; 806 ((U8*)dst_pixels)[2] = src[0];
@@ -813,10 +828,16 @@ BOOL LLImageTGA::decodeTruecolorRle15( LLImageRaw* raw_image )
813 U8* dst = raw_image->getData(); 828 U8* dst = raw_image->getData();
814 U8* src = getData() + mDataOffset; 829 U8* src = getData() + mDataOffset;
815 830
831 U8* last_src = src + getDataSize();
816 U8* last_dst = dst + getComponents() * (getHeight() * getWidth() - 1); 832 U8* last_dst = dst + getComponents() * (getHeight() * getWidth() - 1);
833
817 while( dst <= last_dst ) 834 while( dst <= last_dst )
818 { 835 {
819 // Read RLE block header 836 // Read RLE block header
837
838 if (src >= last_src)
839 return FALSE;
840
820 U8 block_header_byte = *src; 841 U8 block_header_byte = *src;
821 src++; 842 src++;
822 843
@@ -826,6 +847,9 @@ BOOL LLImageTGA::decodeTruecolorRle15( LLImageRaw* raw_image )
826 // Encoded (duplicate-pixel) block 847 // Encoded (duplicate-pixel) block
827 do 848 do
828 { 849 {
850 if (src + 2 >= last_src)
851 return FALSE;
852
829 decodeTruecolorPixel15( dst, src ); // slow 853 decodeTruecolorPixel15( dst, src ); // slow
830 dst += 3; 854 dst += 3;
831 block_pixel_count--; 855 block_pixel_count--;
@@ -838,6 +862,9 @@ BOOL LLImageTGA::decodeTruecolorRle15( LLImageRaw* raw_image )
838 // Unencoded block 862 // Unencoded block
839 do 863 do
840 { 864 {
865 if (src + 2 >= last_src)
866 return FALSE;
867
841 decodeTruecolorPixel15( dst, src ); 868 decodeTruecolorPixel15( dst, src );
842 dst += 3; 869 dst += 3;
843 src += 2; 870 src += 2;
@@ -859,10 +886,16 @@ BOOL LLImageTGA::decodeTruecolorRle24( LLImageRaw* raw_image )
859 U8* dst = raw_image->getData(); 886 U8* dst = raw_image->getData();
860 U8* src = getData() + mDataOffset; 887 U8* src = getData() + mDataOffset;
861 888
889 U8* last_src = src + getDataSize();
862 U8* last_dst = dst + getComponents() * (getHeight() * getWidth() - 1); 890 U8* last_dst = dst + getComponents() * (getHeight() * getWidth() - 1);
891
863 while( dst <= last_dst ) 892 while( dst <= last_dst )
864 { 893 {
865 // Read RLE block header 894 // Read RLE block header
895
896 if (src >= last_src)
897 return FALSE;
898
866 U8 block_header_byte = *src; 899 U8 block_header_byte = *src;
867 src++; 900 src++;
868 901
@@ -872,6 +905,8 @@ BOOL LLImageTGA::decodeTruecolorRle24( LLImageRaw* raw_image )
872 // Encoded (duplicate-pixel) block 905 // Encoded (duplicate-pixel) block
873 do 906 do
874 { 907 {
908 if (src + 2 >= last_src)
909 return FALSE;
875 dst[0] = src[2]; 910 dst[0] = src[2];
876 dst[1] = src[1]; 911 dst[1] = src[1];
877 dst[2] = src[0]; 912 dst[2] = src[0];
@@ -886,6 +921,9 @@ BOOL LLImageTGA::decodeTruecolorRle24( LLImageRaw* raw_image )
886 // Unencoded block 921 // Unencoded block
887 do 922 do
888 { 923 {
924 if (src + 2 >= last_src)
925 return FALSE;
926
889 dst[0] = src[2]; 927 dst[0] = src[2];
890 dst[1] = src[1]; 928 dst[1] = src[1];
891 dst[2] = src[0]; 929 dst[2] = src[0];
@@ -908,16 +946,25 @@ BOOL LLImageTGA::decodeTruecolorRle8( LLImageRaw* raw_image )
908 U8* dst = raw_image->getData(); 946 U8* dst = raw_image->getData();
909 U8* src = getData() + mDataOffset; 947 U8* src = getData() + mDataOffset;
910 948
949 U8* last_src = src + getDataSize();
911 U8* last_dst = dst + getHeight() * getWidth() - 1; 950 U8* last_dst = dst + getHeight() * getWidth() - 1;
951
912 while( dst <= last_dst ) 952 while( dst <= last_dst )
913 { 953 {
914 // Read RLE block header 954 // Read RLE block header
955
956 if (src >= last_src)
957 return FALSE;
958
915 U8 block_header_byte = *src; 959 U8 block_header_byte = *src;
916 src++; 960 src++;
917 961
918 U8 block_pixel_count = (block_header_byte & 0x7F) + 1; 962 U8 block_pixel_count = (block_header_byte & 0x7F) + 1;
919 if( block_header_byte & 0x80 ) 963 if( block_header_byte & 0x80 )
920 { 964 {
965 if (src >= last_src)
966 return FALSE;
967
921 // Encoded (duplicate-pixel) block 968 // Encoded (duplicate-pixel) block
922 memset( dst, *src, block_pixel_count ); 969 memset( dst, *src, block_pixel_count );
923 dst += block_pixel_count; 970 dst += block_pixel_count;
@@ -928,6 +975,9 @@ BOOL LLImageTGA::decodeTruecolorRle8( LLImageRaw* raw_image )
928 // Unencoded block 975 // Unencoded block
929 do 976 do
930 { 977 {
978 if (src >= last_src)
979 return FALSE;
980
931 *dst = *src; 981 *dst = *src;
932 dst++; 982 dst++;
933 src++; 983 src++;