From aba8387202cf506f8b51c26489f808d3d0ce048c Mon Sep 17 00:00:00 2001 From: Mateusz Klatecki <47118568+MateuszKlatecki@users.noreply.github.com> Date: Tue, 29 Oct 2024 13:00:35 +0100 Subject: [PATCH] Add check for byte code table size (#170) --- MetadataProcessor.Shared/Tables/nanoByteCodeTable.cs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/MetadataProcessor.Shared/Tables/nanoByteCodeTable.cs b/MetadataProcessor.Shared/Tables/nanoByteCodeTable.cs index e5cc2c6..ce49a0c 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( } } } +