From 0b6546012a446abe7d3c5d8c2319097800f8f3af Mon Sep 17 00:00:00 2001 From: merlokk <807634+merlokk@users.noreply.github.com> Date: Tue, 27 Jul 2021 18:28:41 +0300 Subject: [PATCH] fix crc search with padding --- client/src/mifare/desfirecrypto.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/client/src/mifare/desfirecrypto.c b/client/src/mifare/desfirecrypto.c index 79604f5eb..e1015c2d8 100644 --- a/client/src/mifare/desfirecrypto.c +++ b/client/src/mifare/desfirecrypto.c @@ -124,7 +124,8 @@ size_t DesfireSearchCRCPos(uint8_t *data, size_t datalen, uint8_t respcode, uint uint8_t crcdata[1024] = {0}; size_t crcposfound = 0; - for (int i = 0; i < crclen + 1; i++) { + // crc may be 00..00 and at the end of file may be padding 0x80. so we search from last zero to crclen + 2 (one for crc=0 and one for padding 0x80) + for (int i = 0; i < crclen + 2; i++) { if (crcpos - i == 0) break; if (crcpos - i + crclen > datalen)