| 4661 | } |
| 4662 | |
| 4663 | static unsigned readChunk_iCCP(LodePNGInfo* info, const LodePNGDecoderSettings* decoder, |
| 4664 | const unsigned char* data, size_t chunkLength) { |
| 4665 | unsigned error = 0; |
| 4666 | unsigned i; |
| 4667 | size_t size = 0; |
| 4668 | /*copy the object to change parameters in it*/ |
| 4669 | LodePNGDecompressSettings zlibsettings = decoder->zlibsettings; |
| 4670 | |
| 4671 | unsigned length, string2_begin; |
| 4672 | |
| 4673 | info->iccp_defined = 1; |
| 4674 | if(info->iccp_name) lodepng_clear_icc(info); |
| 4675 | |
| 4676 | for(length = 0; length < chunkLength && data[length] != 0; ++length) ; |
| 4677 | if(length + 2 >= chunkLength) return 75; /*no null termination, corrupt?*/ |
| 4678 | if(length < 1 || length > 79) return 89; /*keyword too short or long*/ |
| 4679 | |
| 4680 | info->iccp_name = (char*)lodepng_malloc(length + 1); |
| 4681 | if(!info->iccp_name) return 83; /*alloc fail*/ |
| 4682 | |
| 4683 | info->iccp_name[length] = 0; |
| 4684 | for(i = 0; i != length; ++i) info->iccp_name[i] = (char)data[i]; |
| 4685 | |
| 4686 | if(data[length + 1] != 0) return 72; /*the 0 byte indicating compression must be 0*/ |
| 4687 | |
| 4688 | string2_begin = length + 2; |
| 4689 | if(string2_begin > chunkLength) return 75; /*no null termination, corrupt?*/ |
| 4690 | |
| 4691 | length = (unsigned)chunkLength - string2_begin; |
| 4692 | zlibsettings.max_output_size = decoder->max_icc_size; |
| 4693 | error = zlib_decompress(&info->iccp_profile, &size, 0, |
| 4694 | &data[string2_begin], |
| 4695 | length, &zlibsettings); |
| 4696 | /*error: ICC profile larger than decoder->max_icc_size*/ |
| 4697 | if(error && size > zlibsettings.max_output_size) error = 113; |
| 4698 | info->iccp_profile_size = size; |
| 4699 | if(!error && !info->iccp_profile_size) error = 100; /*invalid ICC profile size*/ |
| 4700 | return error; |
| 4701 | } |
| 4702 | #endif /*LODEPNG_COMPILE_ANCILLARY_CHUNKS*/ |
| 4703 | |
| 4704 | unsigned lodepng_inspect_chunk(LodePNGState* state, size_t pos, |
no test coverage detected