Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Change numLocalBytes to u32#500

Open
dianqk wants to merge 1 commit intowasm3:mainfrom
dianqk:numLocalBytes-truncation-loss
Open

Change numLocalBytes to u32#500
dianqk wants to merge 1 commit intowasm3:mainfrom
dianqk:numLocalBytes-truncation-loss

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. :)


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

Comments