Skip to content
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

native runtime: implement memory bounds check #751

Merged
merged 4 commits into from
Dec 7, 2024
Merged

Conversation

yamt
Copy link
Contributor

@yamt yamt commented Aug 14, 2024

Fixes:
#750
#709

@aduros aduros self-requested a review August 31, 2024 16:14
@JerwuQu
Copy link
Contributor

JerwuQu commented Dec 3, 2024

@aduros could you take a look at this?

Comment on lines +132 to +134
uint32_t bpp = (int)bpp2 + 1;
uint32_t nbits = mul_u32_with_overflow_check(mul_u32_with_overflow_check(width, height), bpp);
bounds_check(sprite, nbits / 8);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like the bounds check here, but do we necessarily need to do an overflow checked multiply? I think we can live with possible overflows, as long as it doesn't allow out of bounds access somehow?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

to implement bounds check that way, we need to make this module (runtime.c) know the implementation details of w4_framebufferBlit. or, implement bounds check in w4_framebufferBlit itself.

IMO, it's simpler to perform overflow checks here.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I see. Passing huge values for width/height here that result in an overflow here would fool the bounds check and result in OOB in w4_framebufferBlit. Nice catch!

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.

3 participants