diff --git a/MetadataProcessor.Shared/Tables/nanoByteCodeTable.cs b/MetadataProcessor.Shared/Tables/nanoByteCodeTable.cs index e5cc2c63..ce49a0c1 100644 --- a/MetadataProcessor.Shared/Tables/nanoByteCodeTable.cs +++ b/MetadataProcessor.Shared/Tables/nanoByteCodeTable.cs @@ -82,6 +82,12 @@ public ushort GetMethodId( var byteCode = CreateByteCode(method); + // sanity check for RVA overflow + if (_lastAvailableRva + byteCode.Length > ushort.MaxValue) + { + throw new InvalidOperationException($"Byte code table overflow in assembly '{_context.AssemblyDefinition.Name}'. It's impossible to compile such a large assembly."); + } + _methods.Add(method); _lastAvailableRva += (ushort)byteCode.Length; @@ -161,3 +167,4 @@ private byte[] CreateByteCode( } } } +