Skip to content

Commit

Permalink
apply fix for v3
Browse files Browse the repository at this point in the history
  • Loading branch information
iceman1001 committed Oct 30, 2023
1 parent b50b405 commit 9835543
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions client/src/fileutils.c
Original file line number Diff line number Diff line change
Expand Up @@ -1157,7 +1157,8 @@ int loadFileJSONex(const char *preferredName, void *data, size_t maxdatalen, siz
uint8_t block[MFBLOCK_SIZE] = {0}; // ensure zero-filled when partial block of data read
JsonLoadBufAsHex(root, blocks, block, MFBLOCK_SIZE, &len);
if (!len) {
PrintAndLogEx(WARNING, "WARNING: json %s block %d has zero-length data ... file parsing stopped", ctype, i);
PrintAndLogEx(WARNING, "WARNING: json %s block %d has zero-length data", ctype, i);
PrintAndLogEx(INFO, "file parsing stopped");
break;
} else if (len != MFBLOCK_SIZE) {
PrintAndLogEx(WARNING, "WARNING: json %s block %d only has %d bytes, expected %d (will fill with zero data)", ctype, i, len, MFBLOCK_SIZE);
Expand All @@ -1182,21 +1183,27 @@ int loadFileJSONex(const char *preferredName, void *data, size_t maxdatalen, siz
*datalen = MFU_DUMP_PREFIX_LENGTH;

size_t sptr = 0;
for (int i = 0; i < maxdatalen; i++) {

// load blocks (i) from 0..N, but check sptr against total data length, not `i`
for (int i = 0; sptr < maxdatalen; i++) {
if (sptr + MFBLOCK_SIZE > maxdatalen) {
PrintAndLogEx(ERR, "loadFileJSONex: maxdatalen=%4d (%04x) block (i)=%4d (%04x) sptr=%4d (%04x) -- exceeded maxdatalen", maxdatalen, maxdatalen, i, i, sptr, sptr);
retval = PM3_EMALLOC;
goto out;
}

snprintf(blocks, sizeof(blocks), "$.blocks.%d", i);
uint8_t block[MFBLOCK_SIZE];
uint8_t block[MFBLOCK_SIZE] = {0}; // ensure zero-filled when partial block of data read
JsonLoadBufAsHex(root, blocks, block, MFBLOCK_SIZE, &len);
if (!len)
if (!len) {
PrintAndLogEx(WARNING, "WARNING: json %s block %d has zero-length data", ctype, i);
PrintAndLogEx(INFO, "file parsing stopped");
break;
} else if (len != MFBLOCK_SIZE) {
PrintAndLogEx(WARNING, "WARNING: json %s block %d only has %d bytes, expected %d (will fill with zero data)", ctype, i, len, MFBLOCK_SIZE);
}

memcpy(&udata.bytes[sptr], block, MFBLOCK_SIZE);
sptr += len;
sptr += MFBLOCK_SIZE; // always increment pointer by the full block size, even if only partial data read from dump file
}

*datalen = sptr;
Expand Down

0 comments on commit 9835543

Please sign in to comment.