From 1d87a6c1926345d89a7e3f3c1efb7852b73c0947 Mon Sep 17 00:00:00 2001 From: iceman1001 Date: Sun, 30 Aug 2026 13:33:50 +0200 Subject: [PATCH] chunk CMD_READ_MEM_DOWNLOADED by the OLD frame size reply_old clamps its payload to PM3_CMD_DATA_SIZE_OLD but the sender still chunked by PM3_CMD_DATA_SIZE. Identical today, but if the NG size moves the chunk would be built oversized, truncated on the wire, and still announced at full length in oldarg[1] - the client would copy past the valid bytes and advance by the wrong stride. Bound the client's OLD download branch by the same constant. --- armsrc/appmain.c | 6 ++++-- client/src/comms.c | 3 +++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/armsrc/appmain.c b/armsrc/appmain.c index ee9909615..4ffebcff4 100644 --- a/armsrc/appmain.c +++ b/armsrc/appmain.c @@ -3221,8 +3221,10 @@ static void PacketReceived(PacketCommandNG *packet) { } if (isok) { - for (size_t pos = 0; pos < count; pos += PM3_CMD_DATA_SIZE) { - size_t len = MIN((count - pos), PM3_CMD_DATA_SIZE); + // CMD_READ_MEM_DOWNLOADED is an OLD frame, also served by bootrom.c. + // Chunk by what reply_old can carry, not by the NG payload size. + for (size_t pos = 0; pos < count; pos += PM3_CMD_DATA_SIZE_OLD) { + size_t len = MIN((count - pos), PM3_CMD_DATA_SIZE_OLD); isok = (reply_old(CMD_READ_MEM_DOWNLOADED, pos, len, 0, &base[offset + pos], len) == PM3_SUCCESS); if (isok == false) { Dbprintf("transfer to client failed :: | pos %u len %u", pos, len); diff --git a/client/src/comms.c b/client/src/comms.c index 33cf760ff..a40f8fdc1 100644 --- a/client/src/comms.c +++ b/client/src/comms.c @@ -1289,6 +1289,9 @@ static bool dl_it(uint8_t *dest, uint32_t bytes, PacketResponseNG *response, siz offset = response->oldarg[0]; copy_bytes = response->oldarg[1]; src = response->data.asBytes; + // an OLD frame carries at most PM3_CMD_DATA_SIZE_OLD valid bytes, + // whatever oldarg[1] claims + copy_bytes = MIN(copy_bytes, (uint32_t)PM3_CMD_DATA_SIZE_OLD); } copy_bytes = MIN(bytes - bytes_completed, copy_bytes);