| 1039 | } |
| 1040 | |
| 1041 | PNG_INFO *PNG_decode(/* const*/ UINT8 *in, UINT32 size) |
| 1042 | { |
| 1043 | UINT32 pos ; |
| 1044 | VECTOR_8 *idat; |
| 1045 | BOOLEAN IEND; //,known_type; |
| 1046 | UINT32 bpp; |
| 1047 | PNG_INFO *info; |
| 1048 | VECTOR_8 *scanlines; // now the out buffer will be filled |
| 1049 | UINT32 bytewidth, outlength ; |
| 1050 | UINT8 *out_data; |
| 1051 | |
| 1052 | PNG_error = 0; |
| 1053 | |
| 1054 | if (size == 0 || in == 0) |
| 1055 | { |
| 1056 | PNG_error = 48; // the given data is empty |
| 1057 | DBG("the given data is empty\n"); |
| 1058 | return NULL; |
| 1059 | } |
| 1060 | info = PNG_info_new(); |
| 1061 | PNG_readPngHeader(info, in, size); |
| 1062 | if (PNG_error){ |
| 1063 | DBG("readPngHeader PNG_error=%d\n", PNG_error); |
| 1064 | return NULL; |
| 1065 | } |
| 1066 | pos = 33; // first byte of the first chunk after the header |
| 1067 | idat = NULL; // the data from idat chunks |
| 1068 | IEND = FALSE; |
| 1069 | // known_type = TRUE; |
| 1070 | info->key_defined = FALSE; |
| 1071 | // loop through the chunks, ignoring unknown chunks and stopping at IEND chunk. IDAT data is |
| 1072 | // put at the start of the in buffer |
| 1073 | while (!IEND) |
| 1074 | { |
| 1075 | UINT32 i, j; |
| 1076 | UINT32 chunkLength ; |
| 1077 | UINT32 chunkType; |
| 1078 | UINT32 offset = 0; |
| 1079 | if (pos + 8 >= size) |
| 1080 | { |
| 1081 | PNG_error = 30; // error: size of the in buffer too small to contain next chunk |
| 1082 | DBG("error: size of the in buffer too small to contain next chunk size=%d\n", size); |
| 1083 | return NULL; |
| 1084 | } |
| 1085 | chunkLength = PNG_read32bitInt(&in[pos]); //big endian? Yes! |
| 1086 | pos += 4; |
| 1087 | if (chunkLength > 0x7fffffff) |
| 1088 | { |
| 1089 | PNG_error = 63; |
| 1090 | return NULL; |
| 1091 | } |
| 1092 | if (pos + chunkLength >= size) { |
| 1093 | PNG_error = 35; // error: size of the in buffer too small to contain next chunk |
| 1094 | return NULL; |
| 1095 | } |
| 1096 | // chunkType = *(UINT32 *) &in[pos]; |
| 1097 | chunkType = PNG_read32bitLE(&in[pos]); //read as LE to compare with our constants |
| 1098 | switch (chunkType) { |
no test coverage detected