-
Notifications
You must be signed in to change notification settings - Fork 170
Test failures under GCC13&14 #233
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
I've done some very hacky debugging and found a buffer underflow:
with these changes the sanitizer warnings go away. |
Hey all! I haven't had much time to work on edlib recently as I am occupied with other projects, so I am a bit out of it, but I am happy to help get this resolved. If you want to create a PR and help me understand exactly what it does, I would be happy to merge it. Some questions for start:
|
I'll try getting your CI testing a debugoptimized build with UB- and ASAN. #234 |
@Martinsos what's the rationale for all the "naked"/raw pointers? Using a |
Hah no good rationale: I wrote this code more than 10 years ago on my last year of masters, I wouldn't say I was writing bad code, I was paying a lot of attention to keeping it clean, but my C/C++ knowledge wasn't at a very high level. Neither is it today, last years I am mostly coding in Haskell and Javascript/Typescript. Which is what makes it even a bit hard for me to track the conversation in this very github issue, as I am out of the loop on he professional C++ dev in the last X years. But I can probably catch up stuff quickly if provided with some extra context, and am happy to support improvements! |
Btw at one point I did create an issue to use smart pointers: #84 -> but at that point I probably had a better idea what I wanted to do then I have now, I would need some reminding. |
I took a look at this previously and I believe this is a GCC bug because:
At the time I didn't have time to try and make a minimized repro case, but if you're hitting it for 2 versions of GCC then it might be worth trying to make one. FWIW we've ran (part of) this library through sanitizers as part of dorado for the past 2 years and haven't caught anything, though obviously that doesn't mean that there isn't a problem hiding in an edge case! |
Use the following patch:
compile the codebase using
with the stacktrace showing
The problem really is the "undershoot" in while (lastBlock >= firstBlock && bl->score >= k + WORD_SIZE) {
lastBlock--; bl--; Peq_c--;
} which is UB. Logically, that whole loop makes no sense, since if you ignore the second term, after the loop |
@SoapZA Good catch. However note the increment that follows: Lines 624 to 630 in 1e8f7ee
For all intents and purposes this undoes the out-of-bounds decrement. But from a C++ language lawyer side this is indeed UB since it's no longer pointing into the addressable area (or the past the end iterator) that I guess a "fix" would be to pad Block* blocks_with_padding = new Block[1 + maxNumBlocks];
Block* blocks = blocks_with_padding + 1; Obviously a neater fix would be preferred, but that explains why GCC (and only GCC) is complaining about it - recent versions have improved object bounds checks (fortification stuff). I wonder if using |
|
other idea: what about going away from pointers and just using indices? those can obviously be negative and are independent of GCC's object range checks, and they make indirection through |
The following code doesn't trigger for me anymore:
|
* Forming a pointer "one before" the start of a range is UB: https://devblogs.microsoft.com/oldnewthing/20211112-00/?p=105908 * GCC 13's UBSAN detects this now: https://gcc.gnu.org/cgit/gcc/commit?id=28896b38fabce8 * By using a (signed) index, we can avoid forming invalid pointers. Fixes Martinsos#233
Thanks @armintoepfer @blawrence-ont and @SoapZA: thank you all for this discussion, I learned quite a bit, and I believe this is fixed now on A couple of thoughts:
|
Thank you for your work on edlib. We've been using it over many years.
Today, I've tried compiling and testing edlib with GCC 13 and 14, but hit a wall. There seems to be a buffer overflow.
Reproduce:
Error message:
The text was updated successfully, but these errors were encountered: