summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMaurice <maurice.henke@protonmail.com>2021-04-09 16:35:05 +0200
committerMaurice <maurice.henke@protonmail.com>2021-04-09 16:35:05 +0200
commit2a0612962b848fae38c3da5a91144360ee9a3997 (patch)
treec3debbf2c0a8d00557c08b86af053a0489246e4b
parent8b6c4a2bc1ffd0d50f753f33d952259add9ddb4f (diff)
Fixed small length adjustment issue
Previously the adjustedLength could technically be out of bounds. For example: Reading 10 bytes from offset 510 would cause adjusted offset to be 0 and adjusted length to be 512 (min) This reads 0-512 bytes into the buffer but tries to output 510-520. This shouldn't happen anymore.
-rw-r--r--source/tools.cpp2
1 files changed, 1 insertions, 1 deletions
diff --git a/source/tools.cpp b/source/tools.cpp
index bc94b4a..7ab8bb4 100644
--- a/source/tools.cpp
+++ b/source/tools.cpp
@@ -75,7 +75,7 @@ namespace libtp::tools
// Since we can only read in and at increments of CARD_READ_SIZE do this to calculate the region we require
int32_t adjustedOffset = ( offset / CARD_READ_SIZE ) * CARD_READ_SIZE;
- int32_t adjustedLength = ( 1 + ( ( length - 1 ) / CARD_READ_SIZE ) ) * CARD_READ_SIZE;
+ int32_t adjustedLength = ( 1 + ( ( offset - adjustedOffset + length - 1 ) / CARD_READ_SIZE ) ) * CARD_READ_SIZE;
// Buffer might not be adjusted to the new length so create a temporary data buffer
uint8_t* data = new uint8_t[adjustedLength];