MCPcopy Create free account
hub / github.com/OpenXcom/OpenXcom / readChunk_zTXt

Function readChunk_zTXt

src/lodepng.cpp:4391–4437  ·  view source on GitHub ↗

compressed text chunk (zTXt)*/

Source from the content-addressed store, hash-verified

4389
4390/*compressed text chunk (zTXt)*/
4391static unsigned readChunk_zTXt(LodePNGInfo* info, const LodePNGDecompressSettings* zlibsettings,
4392 const unsigned char* data, size_t chunkLength)
4393{
4394 unsigned error = 0;
4395 unsigned i;
4396
4397 unsigned length, string2_begin;
4398 char *key = 0;
4399 ucvector decoded;
4400
4401 ucvector_init(&decoded);
4402
4403 while(!error) /*not really a while loop, only used to break on error*/
4404 {
4405 for(length = 0; length < chunkLength && data[length] != 0; length++) ;
4406 if(length + 2 >= chunkLength) CERROR_BREAK(error, 75); /*no null termination, corrupt?*/
4407 if(length < 1 || length > 79) CERROR_BREAK(error, 89); /*keyword too short or long*/
4408
4409 key = (char*)lodepng_malloc(length + 1);
4410 if(!key) CERROR_BREAK(error, 83); /*alloc fail*/
4411
4412 key[length] = 0;
4413 for(i = 0; i < length; i++) key[i] = data[i];
4414
4415 if(data[length + 1] != 0) CERROR_BREAK(error, 72); /*the 0 byte indicating compression must be 0*/
4416
4417 string2_begin = length + 2;
4418 if(string2_begin > chunkLength) CERROR_BREAK(error, 75); /*no null termination, corrupt?*/
4419
4420 length = chunkLength - string2_begin;
4421 /*will fail if zlib error, e.g. if length is too small*/
4422 error = zlib_decompress(&decoded.data, &decoded.size,
4423 (unsigned char*)(&data[string2_begin]),
4424 length, zlibsettings);
4425 if(error) break;
4426 ucvector_push_back(&decoded, 0);
4427
4428 error = lodepng_add_text(info, key, (char*)decoded.data);
4429
4430 break;
4431 }
4432
4433 lodepng_free(key);
4434 ucvector_cleanup(&decoded);
4435
4436 return error;
4437}
4438
4439/*international text chunk (iTXt)*/
4440static unsigned readChunk_iTXt(LodePNGInfo* info, const LodePNGDecompressSettings* zlibsettings,

Callers 1

decodeGenericFunction · 0.85

Calls 7

ucvector_initFunction · 0.85
lodepng_mallocFunction · 0.85
zlib_decompressFunction · 0.85
ucvector_push_backFunction · 0.85
lodepng_add_textFunction · 0.85
lodepng_freeFunction · 0.85
ucvector_cleanupFunction · 0.85

Tested by

no test coverage detected