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

Fix handling of data count without data section #2432

Merged
merged 5 commits into from
Sep 24, 2024

Conversation

SoniEx2
Copy link
Contributor

@SoniEx2 SoniEx2 commented Jun 19, 2024

Closes #2436
Fixes #2310
Fixes #2311
Fixes #2431

@SoniEx2
Copy link
Contributor Author

SoniEx2 commented Sep 12, 2024

upstreamed WebAssembly/spec#1801 now to make a fix...

@SoniEx2 SoniEx2 marked this pull request as draft September 12, 2024 15:12
@SoniEx2 SoniEx2 changed the title Add test for #2431, mark as broken/skip for now Fix handling of data count without data section Sep 12, 2024
@SoniEx2 SoniEx2 marked this pull request as ready for review September 12, 2024 15:53
@SoniEx2
Copy link
Contributor Author

SoniEx2 commented Sep 12, 2024

@keithw @sbc100

for (Index i = 0; i < num_data_segments; ++i) {
ERROR_UNLESS(
data_count_ == kInvalidIndex || data_count_ == num_data_segments_,
"data segment count does not equal count in DataCount section");
Copy link
Member

Choose a reason for hiding this comment

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

I think this check can not be removed, since the module level check will always catch this error.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

do we want to keep parsing when we encounter a malformed module?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

we think doing this check early is important

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@sbc100 ping?

Copy link
Member

Choose a reason for hiding this comment

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

we think doing this check early is important

Can you explain why? It seems redundant to me.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Whoops, missed this. Uh, we think, because the module is malformed, it's better to exit early if we can. Tho the more important thing is that a malformed module shouldn't crash the parser, we guess.

Copy link
Member

Choose a reason for hiding this comment

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

I agree the parse should not crash. Are you saying that if you remove these 3 lines the parser will crash? Where/why?

Copy link
Member

Choose a reason for hiding this comment

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

, because the module is malformed, it's better to exit early if we can.

I think delaying the error would be fine in this case, it it means we can avoid the duplication.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Tweaked and rebased, let's see what CI has to say.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

well.

based on the changes to the error messages, we prefer the duplicated checks.

// This must be checked at the end, in case the data section was omitted.
ERROR_UNLESS(
data_count_ == kInvalidIndex || data_count_ == num_data_segments_,
"data segment count does not equal count in DataCount section");
Copy link
Member

Choose a reason for hiding this comment

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

Ok, if we must have a separate check can we change the wording a little so we can tell which error is being emitted.

How about changing this one to be something like: "Non-zero DataCount section, but not data segments found", and maybe surround this check with if (num_data_segments_ == 0) since that is the only time we need to check for this condition.

@sbc100 sbc100 merged commit 3852498 into WebAssembly:main Sep 24, 2024
18 checks passed
@SoniEx2 SoniEx2 deleted the broken-tests branch September 24, 2024 00:57
@sbc100 sbc100 mentioned this pull request Oct 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants