Skip to content

Fix UBSan error: Shifting 64 bit type by 64 is undefined behaviour#53

Open
DanielG wants to merge 1 commit into
silentbicycle:masterfrom
DanielG:fix-ubsan
Open

Fix UBSan error: Shifting 64 bit type by 64 is undefined behaviour#53
DanielG wants to merge 1 commit into
silentbicycle:masterfrom
DanielG:fix-ubsan

Conversation

@DanielG
Copy link
Copy Markdown

@DanielG DanielG commented Dec 18, 2019

Shifting a type by >=sizeof(type)*8 is undefined behaviour in C. Since
t->prng.buf is overwritten on the next iteration anyways this thankfully
isn't a real bug here.

Fixes #52

Shifting a type by >=sizeof(type)*8 is undefined behaviour in C. Since
t->prng.buf is overwritten on the next iteration anyways this thankfully
isn't a real bug here.

Fixes silentbicycle#52
@silentbicycle
Copy link
Copy Markdown
Owner

Being able to take more than 64 bits here could be a sign of a deeper issue. Thanks for reporting this.

I probably won't get to reviewing this closely for a bit because of the holidays, but when I do I'll retarget the PR for the develop branch.

@dcreager
Copy link
Copy Markdown

This just bit me too! I think the fix is correct — there's no attempt to take more than 64 bits, which you're right would be a deeper issue. It's just that if you take exactly 64 bits, then there's no need to shift anything in prng.buf, since you've just consumed it all, and will replace it with a new random uint64_t the next time through the loop. The if guard in this patch checks exactly that.

@notxvilka
Copy link
Copy Markdown

Being able to take more than 64 bits here could be a sign of a deeper issue. Thanks for reporting this.

I probably won't get to reviewing this closely for a bit because of the holidays, but when I do I'll retarget the PR for the develop branch.

@silentbicycle have you had a chance to look at it?

@silentbicycle
Copy link
Copy Markdown
Owner

Not really.

The general state of this project is that I started working on a multi-process version, because it benefits tremendously from using multiple CPU cores for parallel search, but along the way the codebase grew about 20x as large, I got massively burnt out on working on it, and haven't gotten back to it for several years. Changing life circumstances have given me little time for open source projects these days.

I will probably eventually restart the project, but with a completely clean start and some major rethinking of the interfaces. The core library may be in Rust, since that will provide a lot of infrastructure I had to implement myself, though I want the library be usable for testing and fuzzing both C and Rust, possibly other languages with adapter libraries. (I'd probably maintain one for Lua, since those are the three languages I tend to use most these days.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Running with UBSan throws runtime error regarding bitshift

4 participants