text chunk (tEXt)*/
| 4346 | |
| 4347 | /*text chunk (tEXt)*/ |
| 4348 | static unsigned readChunk_tEXt(LodePNGInfo* info, const unsigned char* data, size_t chunkLength) |
| 4349 | { |
| 4350 | unsigned error = 0; |
| 4351 | char *key = 0, *str = 0; |
| 4352 | unsigned i; |
| 4353 | |
| 4354 | while(!error) /*not really a while loop, only used to break on error*/ |
| 4355 | { |
| 4356 | unsigned length, string2_begin; |
| 4357 | |
| 4358 | length = 0; |
| 4359 | while(length < chunkLength && data[length] != 0) length++; |
| 4360 | /*even though it's not allowed by the standard, no error is thrown if |
| 4361 | there's no null termination char, if the text is empty*/ |
| 4362 | if(length < 1 || length > 79) CERROR_BREAK(error, 89); /*keyword too short or long*/ |
| 4363 | |
| 4364 | key = (char*)lodepng_malloc(length + 1); |
| 4365 | if(!key) CERROR_BREAK(error, 83); /*alloc fail*/ |
| 4366 | |
| 4367 | key[length] = 0; |
| 4368 | for(i = 0; i < length; i++) key[i] = data[i]; |
| 4369 | |
| 4370 | string2_begin = length + 1; /*skip keyword null terminator*/ |
| 4371 | |
| 4372 | length = chunkLength < string2_begin ? 0 : chunkLength - string2_begin; |
| 4373 | str = (char*)lodepng_malloc(length + 1); |
| 4374 | if(!str) CERROR_BREAK(error, 83); /*alloc fail*/ |
| 4375 | |
| 4376 | str[length] = 0; |
| 4377 | for(i = 0; i < length; i++) str[i] = data[string2_begin + i]; |
| 4378 | |
| 4379 | error = lodepng_add_text(info, key, str); |
| 4380 | |
| 4381 | break; |
| 4382 | } |
| 4383 | |
| 4384 | lodepng_free(key); |
| 4385 | lodepng_free(str); |
| 4386 | |
| 4387 | return error; |
| 4388 | } |
| 4389 | |
| 4390 | /*compressed text chunk (zTXt)*/ |
| 4391 | static unsigned readChunk_zTXt(LodePNGInfo* info, const LodePNGDecompressSettings* zlibsettings, |
no test coverage detected