Skip to content

Commit

Permalink
Fix: properly handle 0 length kvdata.
Browse files Browse the repository at this point in the history
  • Loading branch information
MarkCallow committed Apr 10, 2021
1 parent b7563ea commit aee7a1c
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions lib/info.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ printKVData(ktx_uint8_t* pKvd, ktx_uint32_t kvdLen)
KTX_error_code result;
ktxHashList kvDataHead = 0;

assert(pKvd != NULL);
assert(pKvd != NULL && kvdLen > 0);

result = ktxHashList_Deserialize(&kvDataHead,
kvdLen, pKvd);
Expand Down Expand Up @@ -398,11 +398,15 @@ printKTX2Info2(ktxStream* stream, KTX_header2* pHeader)
printDFD(DFD);
free(DFD);

fprintf(stdout, "\nKeyValue Data\n\n");
metadata = malloc(pHeader->keyValueData.byteLength);
stream->read(stream, metadata, pHeader->keyValueData.byteLength);
printKVData(metadata, pHeader->keyValueData.byteLength);
free(metadata);
if (pHeader->keyValueData.byteLength) {
fprintf(stdout, "\nKey/Value Data\n\n");
metadata = malloc(pHeader->keyValueData.byteLength);
stream->read(stream, metadata, pHeader->keyValueData.byteLength);
printKVData(metadata, pHeader->keyValueData.byteLength);
free(metadata);
} else {
fprintf(stdout, "\nNo Key/Value data.\n");
}

if (pHeader->supercompressionGlobalData.byteOffset != 0
&& pHeader->supercompressionGlobalData.byteLength != 0) {
Expand Down

0 comments on commit aee7a1c

Please sign in to comment.