[Types] Fix missing inverse check for described field in isValidSupertype#8378
[Types] Fix missing inverse check for described field in isValidSupertype#8378sumleo wants to merge 2 commits intoWebAssembly:mainfrom
Conversation
…type The descriptor field check in isValidSupertype was fully symmetric: if the subtype has no descriptor, then the supertype must also have no descriptor. However, the described field check was missing its else branch, allowing a non-descriptor type to illegally subtype a descriptor type when features are fully enabled. Add the missing else branch so that if the subtype has no describes clause, the supertype must also have no describes clause.
| // describes clause. | ||
| if (super.described) { | ||
| return false; | ||
| } |
There was a problem hiding this comment.
I believe this is not correct, but the spec changed and I'm not sure - @tlively ?
There was a problem hiding this comment.
This is correct! We do not allow this:
(type $foo (descriptor $super) (struct))
(type $super (sub (describes $foo) (struct)))
(type $sub (sub $super) (struct))
That seems pretty bad. Would you be able to upload a fix for that as well? |
This fixes assert_invalid modules being rejected during parsing rather than during validation when they use features like custom descriptors.
|
Added a fix in a4720ef: |
Summary
elsebranch inisValidSupertypefor thedescribedfield check, making it symmetric with the existingdescriptorfield check.describesclause can illegally subtype a type that has adescribesclause (i.e., a descriptor type), as long as all features are enabled.descriptorcheck already handles both directions (if sub has no descriptor, super must also have no descriptor), but thedescribedcheck was missing the inverse direction.Details
In
isValidSupertype(src/wasm/wasm-type.cpp), the validation fordescriptoris fully symmetric:But the
describedcheck was missing the else branch:The spec test at
test/spec/descriptors.wast(lines 152-161) already covers this case with anassert_invalidfor "supertype of non-descriptor type cannot be a descriptor". However, the test currently passes for the wrong reason:wasm-shellre-parsesassert_invalidmodules as quoted text modules without features enabled, soTypeBuilder::build()rejects the module withRequiresCustomDescriptorsbefore ever reachingisValidSupertype. When the module is loaded through the normal inline parse path (with all features enabled), the invalid subtyping relationship is incorrectly accepted.Test plan
wasm-shell test/spec/descriptors.wastpasses all 14 checks (including the one at line 152)