MCPcopy Create free account
hub / github.com/DentonW/DevIL / ParseResources

Function ParseResources

DevIL/src-IL/src/il_psd.cpp:795–855  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

793
794
795ILboolean ParseResources(ILuint ResourceSize, ILubyte *Resources)
796{
797 ILushort ID;
798 ILubyte NameLen;
799 ILuint Size;
800
801 if (Resources == NULL) {
802 ilSetError(IL_INTERNAL_ERROR);
803 return IL_FALSE;
804 }
805
806 while (ResourceSize > 13) { // Absolutely has to be larger than this.
807 if (strncmp("8BIM", (const char*)Resources, 4)) {
808 //return IL_FALSE;
809 return IL_TRUE; // 05-30-2002: May not necessarily mean corrupt data...
810 }
811 Resources += 4;
812
813 ID = *((ILushort*)Resources);
814 BigUShort(&ID);
815 Resources += 2;
816
817 NameLen = *Resources++;
818 // NameLen + the byte it occupies must be padded to an even number, so NameLen must be odd.
819 NameLen = NameLen + (NameLen & 1 ? 0 : 1);
820 Resources += NameLen;
821
822 // Get the resource data size.
823 Size = *((ILuint*)Resources);
824 BigUInt(&Size);
825 Resources += 4;
826
827 ResourceSize -= (4 + 2 + 1 + NameLen + 4);
828
829 switch (ID)
830 {
831 case 0x040F: // ICC Profile
832 if (Size > ResourceSize) { // Check to make sure we are not going past the end of Resources.
833 ilSetError(IL_ILLEGAL_FILE_VALUE);
834 return IL_FALSE;
835 }
836 iCurImage->Profile = (ILubyte*)ialloc(Size);
837 if (iCurImage->Profile == NULL) {
838 return IL_FALSE;
839 }
840 memcpy(iCurImage->Profile, Resources, Size);
841 iCurImage->ProfileSize = Size;
842 break;
843
844 default:
845 break;
846 }
847
848 if (Size & 1) // Must be an even number.
849 Size++;
850 ResourceSize -= Size;
851 Resources += Size;
852 }

Callers 4

ReadGreyFunction · 0.85
ReadIndexedFunction · 0.85
ReadRGBFunction · 0.85
ReadCMYKFunction · 0.85

Calls 1

ilSetErrorFunction · 0.85

Tested by

no test coverage detected