Comments (2)
Thanks for filing it. FWIW, I think the code is safe, but I understand why UBsan is yelling at me. I'm unconditionally decrementing dec_len
in the while loop condition, but if dec_len
starts at zero, then it underflows past zero and that's surprising / sometimes-bad.
In this case nothing outside of the while loop reads dec_len
, and the while loop will be skipped if dec_len
is 0, so it's leaving an underflowed value in its wake but one that's never read by any code.
while (dec_len--) {
cobs_byte_t const byte = src[src_idx];
if (byte) {
dst[dst_idx] = byte;
if (++dst_idx >= enc_max) { return COBS_RET_ERR_EXHAUSTED; }
++code;
}
if ((byte == 0) || (code == 0xFF)) {
dst[dst_code_idx] = (cobs_byte_t)code;
dst_code_idx = dst_idx;
code = 1;
if ((byte == 0) || dec_len) {
if (++dst_idx >= enc_max) { return COBS_RET_ERR_EXHAUSTED; }
} else {
need_advance = !dec_len;
}
}
++src_idx;
}
ctx->cur = dst_idx;
ctx->code = code;
ctx->code_idx = dst_code_idx;
ctx->need_advance = need_advance;
return COBS_RET_SUCCESS;
}
I'll guard against 0 with a success-early-out at the top of the function- even though it's safe right now, it's just begging to give someone a Bad Surprise if they're hacking around in the code, or if I rework it in the future.
from nanocobs.
v0.0.4 release here https://github.com/charlesnicholson/nanocobs/releases/tag/v0.0.4 with this fix and your other overrun fix.
from nanocobs.
Related Issues (9)
- thorough unit tests for `cobs_decode`
- encode API overhaul: incremental encoding HOT 1
- invalid frame case for cobs_inplace_decode HOT 4
- Rewrite `cobs_encode_inc` to support small buffers
- Incremental decoder
- Update docs to new `cobs_decode_inc` and `cobs_encode_inc` functions
- SPDX License headers HOT 1
- Variable length decoding in place, where ends the data? HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from nanocobs.