-
Notifications
You must be signed in to change notification settings - Fork 94
Name section parsing fails for valid wasm #271
Comments
I have dug a little bit into this example and found that the name section looks like this:
So, smth might be wrong with locals names subsection. How was this code obtained? P.S. It works on 0.35.0 because it doesn't parse this locals names subsection :). |
This was the original text:
And translated to wasm (with name section) using wabt's |
@NikVolf It seems that the problem here is that the LocalNameSubsection::deserialize doesn't count the imported functions in max_entry_space. To compare in wabt code which parses the same subsection compares a function id with NumTotalFuncs() result, and in its turn the NumTotalFuncs implemented here takes into account imports as well. P.S. Shall I make a PR to fix it? Also, it seems reasonable to look through the code to find the similar cases with imports. |
Was this fixed by #277? If so, can the above example included in the tests? |
Actually, this snippet is the same as @benediktwerner provided. Because it depends only on the presence of imports. Btw, It was really fixed and can be closed. |
Hmm, I still observe |
--- a/src/elements/name_section.rs
+++ b/src/elements/name_section.rs
@@ -268,7 +268,7 @@ impl LocalNameSubsection {
let max_space = max_signature_args + max_locals;
- let deserialize_locals = |_: u32, rdr: &mut R| IndexMap::deserialize(max_space, rdr);
+ let deserialize_locals = |_: u32, rdr: &mut R| IndexMap::deserialize(usize::MAX, rdr);
let local_names = IndexMap::deserialize_with(
max_entry_space, avoids it, so either my wasm has wrong local names, or something is wrong with |
I think I found it: You are counting diff --git a/src/elements/name_section.rs b/src/elements/name_section.rs
index 7001085..a385f4c 100644
--- a/src/elements/name_section.rs
+++ b/src/elements/name_section.rs
@@ -263,7 +263,7 @@ impl LocalNameSubsection {
let max_locals = module
.code_section()
- .map(|cs| cs.bodies().iter().map(|f| f.locals().len()).max().unwrap_or(0))
+ .map(|cs| cs.bodies().iter().map(|f| f.locals().iter().map(|l| l.count() as usize).max().unwrap_or(0)).max().unwrap_or(0))
.unwrap_or(0);
let max_space = max_signature_args + max_locals; |
the calculation of the largest possible index of locals was not taking compressed locals (`count > 1`) into account. Related to paritytech#271
* Improve parser for name section the calculation of the largest possible index of locals was not taking compressed locals (`count > 1`) into account. Related to #271 * Fix spacing * Sum, not max
Has this fix been released? I've had the same issue on v0.42.2 (latest tagged) |
got the same issue, the wasm was generate from golang. i have try master branch,still have problem. |
maybe better keep use Unparsed part, after all, this bug has existed for two years. If all think it OK, I can have a pr, @nukemandan |
I've open a PR that I think solves this issue, at least what I'm able to replicate. The formatting is a bit messy, if that's important I can try to fix it. Could I get a review? @nukemandan not sure if you're able to review, if not, could you please point me in the right direction? |
@pepyakin could you please tag a new version release with this change? |
This works with 0.35.0 and panics on 0.38.0:
Error snippet:
I'm using Ubuntu 18.0.4.
The text was updated successfully, but these errors were encountered: