mirror of
https://github.com/ratspeak/microReticulum
synced 2026-11-27 13:52:14 +00:00
Fix Bytes hex parsing and Transport receipt culling bugs
- Bytes::assignHex/appendHex: truncate to even length before parsing to prevent reading past buffer on odd-length hex strings - Bytes::mid(): fix off-by-one in bounds check (>= vs >) - Transport: fix receipt culling loop iterating wrong list, which caused stale receipts to accumulate instead of being removed Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
1 parent
838cede2e1
commit
b2dc394623
2 files changed
+21
-8
No files matched your search
+17
-4
@@ -126,6 +126,13 @@ void Bytes::assignHex(const uint8_t* hex, size_t hex_size) {
|
||||
_exclusive = true;
|
||||
return;
|
||||
}
|
||||
// Truncate to even length (hex bytes come in pairs)
|
||||
hex_size &= ~(size_t)1;
|
||||
if (hex_size == 0) {
|
||||
_data = nullptr;
|
||||
_exclusive = true;
|
||||
return;
|
||||
}
|
||||
exclusiveData(false, hex_size / 2);
|
||||
// need to clear data since we're appending below
|
||||
_data->clear();
|
||||
@@ -140,6 +147,11 @@ void Bytes::appendHex(const uint8_t* hex, size_t hex_size) {
|
||||
if (hex == nullptr || hex_size <= 0) {
|
||||
return;
|
||||
}
|
||||
// Truncate to even length (hex bytes come in pairs)
|
||||
hex_size &= ~(size_t)1;
|
||||
if (hex_size == 0) {
|
||||
return;
|
||||
}
|
||||
exclusiveData(true, size() + (hex_size / 2));
|
||||
for (size_t i = 0; i < hex_size; i += 2) {
|
||||
uint8_t byte = (hex[i] % 32 + 9) % 25 * 16 + (hex[i+1] % 32 + 9) % 25;
|
||||
@@ -186,10 +198,11 @@ Bytes Bytes::mid(size_t beginpos, size_t len) const {
|
||||
if (!_data || beginpos >= size()) {
|
||||
return NONE;
|
||||
}
|
||||
if ((beginpos + len) >= size()) {
|
||||
len = (size() - beginpos);
|
||||
}
|
||||
return {data() + beginpos, len};
|
||||
size_t remaining = size() - beginpos;
|
||||
if (len > remaining) {
|
||||
len = remaining;
|
||||
}
|
||||
return {data() + beginpos, len};
|
||||
}
|
||||
|
||||
// to end
|
||||
|
||||
Reference in new issue
Block a user