Possible ArgumentOutOfRangeException when there are 65535 params in metadata table #913
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
github.com/jbevain/cecil@ba9c6c79f5/Mono.Cecil/AssemblyReader.cs (L979-L1003)(Sorry but I'm unable to provide a sample dll.)
We have a big dll which exactly has 65535 parameters in metadata table.

When processing it using cecil, it throw exception like this:
After some debugging I managed to locate the problem:
github.com/jbevain/cecil@ba9c6c79f5/Mono.Cecil/AssemblyReader.cs (L995)When it's trying to read the 65535th (the last) param (it is used in a compiler-generated anonymous method), and
image.GetTableIndexSizereturns 2 (entry < 65536),ReadTableIndexreturns 0,next_index = 0.github.com/jbevain/cecil@ba9c6c79f5/Mono.Cecil/AssemblyReader.cs (L1000)list.Length = next_index - start = 0u - 65535u = 4294901761💥On the other hand, dnlib already handled this problem, so it still works for our dll:
github.com/0xd4d/dnlib@97e07a8f1e/src/DotNet/MD/CompressedMetadata.cs (L143-L157)The magic happens here:

That's a good catch, thank you :)
The magic actually happens here in
dnlib:Thanks for pointing out. In my situation,
endRidwas set to 0 at this line. Then it was set to65535in L153, which I thought was the key to keependRid - startRidcorrect in L156.Hi! @jbevain we have a symmetric issue at Unity, but mono - Mono.Cecil generates an assembly with exactly 65535 fields and loading it in mono results in the crash due to very similar table row usage logic.
Are there any reasons that https://github.com/jbevain/cecil/pull/914 was not merged yet and would be feasible to use
intfor field indices when patching assembly with Cecil? (should I make a new issue for this?)Thanks!
wrt my last comment - I checked what happens if we use large indices when table size is 65535 and it doesn't work as no reader can then read assembly properly. According to the standard large indices are only used for row count 2^16 and above