out of bounds access in DLE encoder #492
Loading…
x
Reference in New Issue
Block a user
No description provided.
Delete Branch "mueller/dle-possible-bugfix"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Found when writing unit tests for Rust.
Rust would not have an array out of bounds access (even for reading) and panicked.
The test for C++ was missing (was added as well) but might not have caught the array out of bounds error.
In the while loop, the encoder might step out of the while loop if encoded index is equal to the source stream length. The problem is that the index will be invalid to use because it is incremented but is still used at line 208
Good catch.
I am wondering if it would be better (and easier to understand for future readers) if we changed the while loop in
decodeStreamEscaped()
similar to the one indecodeStreamNonEscaped()
, where the while loop only protects out of bound reads (as in(encodedIndex < sourceStreamLen) and (decodedIndex < maxDestStreamlen)
) and move the exit conditions completely into the loop, that is checking for STX and ETX.Results would be:
< sourceStreamLen
which I find more intuitiveswitch
might be approptriate)What do you think about this?
I like this idea, it makes the code more understandable. I added it to the PR for now, the unit tests verified that everything is still working
Looks good, minor change below
@ -200,2 +199,3 @@
}
else {
case(STX_CHAR): {
*readLen = ++encodedIndex;
I think this should be
*readLen = encodedIndex;
, we should preserve theSTX
as it might start a new, valid frame.clicked wrong button
possible bugfix for DLE encoderto out of bounds access in DLE encoderlooking good now