Nothing Special   »   [go: up one dir, main page]

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

Change numLocalBytes to u32 #500

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

DianQK
Copy link
Contributor
@DianQK DianQK commented Aug 9, 2024

When we have 8192 i64 locals, the required bytes are 65536.

IIUC, the test cases in the test/regression directory are not actually being tested.

@tommie
Copy link
Contributor
tommie commented Aug 9, 2024

IIUC, the test cases in the test/regression directory are not actually being tested.

No, sorry, I just started adding them for future use as I was fixing security issues.

Agreed it would be good to convert them to .wast and actually run them. :)

@@ -71,7 +71,7 @@ typedef struct M3Function
u16 numRetAndArgSlots;

u16 numLocals; // not including args
u16 numLocalBytes;
u32 numLocalBytes;
Copy link
Contributor
@tommie tommie Aug 9, 2024

Choose a reason for hiding this comment

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

There are many more u16 fields here that are counting slots. A slot is 4 (or 8) bytes, so only increasing this variable isn't going to help much in the general case.

o->function->numLocalBytes = (maxSlot - o->slotFirstLocalIndex) * sizeof (m3slot_t);

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This PR addresses the issue caused by this line. I don't think we need to change the slot count to u32, but I'm not sure which other variable types we might need to adjust. It makes more sense to me to add -fsanitize=integer in the CI.

Copy link
Contributor

Choose a reason for hiding this comment

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

If you use 4 times as many locals as you are using now, you'll wrap around the maxStackSlots slot counter. So just changing this line only moves the problem by a factor of 4, not 2^16. Is that good enough?

It makes more sense to me to add -fsanitize=integer in the CI.

Fixing the overflows (by returning error) and enabling UBSan does sound nice.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If you use 4 times as many locals as you are using now, you'll wrap around the maxStackSlots slot counter. So just changing this line only moves the problem by a factor of 4, not 2^16. Is that good enough?

I can verify that when I set d_m3MaxFunctionStackHeight to 32767, it first encounters m3Err_functionStackOverflow in AllocateSlotsWithinRange.

Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks for checking!

@tommie
Copy link
Contributor
tommie commented Aug 9, 2024

I made #504 for running regression tests. It's unfortunately a large change, splitting run-spec-test.py so the JSON parsing is separate from downloading the spec tests.

@DianQK DianQK force-pushed the numLocalBytes-truncation-loss branch from 689b26a to 4472181 Compare August 10, 2024 06:46
When we have 8192 `i64` locals, the required bytes are 65536.
@DianQK DianQK force-pushed the numLocalBytes-truncation-loss branch from 4472181 to 9172d69 Compare August 10, 2024 06:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants