Skip to content

InvalidOperationException when md rva isn't alignment  #543

Description

@CreateAndInject

public void SetOffset(FileOffset offset, RVA rva) {
// This method can be called twice by NativeModuleWriter. It needs to know the size
// of the final metadata. If it fits in the old location, the new MD will be written
// there (smaller file size). If the new MD doesn't fit in the old location, this
// method gets called a second time with the updated offset + rva.
bool initAll = this.offset == 0;
this.offset = offset;
this.rva = rva;
if (initAll) {
// #Strings heap is initialized in OnBeforeSetOffset()
blobHeap.SetReadOnly();
guidHeap.SetReadOnly();
tablesHeap.SetReadOnly();
pdbHeap.SetReadOnly();
tablesHeap.BigStrings = stringsHeap.IsBig;
tablesHeap.BigBlob = blobHeap.IsBig;
tablesHeap.BigGuid = guidHeap.IsBig;
metadataHeader.Heaps = GetHeaps();
}
metadataHeader.SetOffset(offset, rva);
uint len = metadataHeader.GetFileLength();
offset += len;
rva += len;
foreach (var heap in metadataHeader.Heaps) {
offset = offset.AlignUp(HEAP_ALIGNMENT);
rva = rva.AlignUp(HEAP_ALIGNMENT);
heap.SetOffset(offset, rva);
len = heap.GetFileLength();
offset += len;
rva += len;
}
Debug.Assert(initAll || length == rva - this.rva);
if (!(initAll || length == rva - this.rva))
throw new InvalidOperationException();
length = rva - this.rva;
if (!isStandaloneDebugMetadata && initAll)
UpdateMethodAndFieldRvas();
}

this?

		public void SetOffset(FileOffset offset, RVA rva) {
			uint rem = (uint)rva % HEAP_ALIGNMENT;
                        ......
			foreach (var heap in metadataHeader.Heaps) {
				offset = (offset - rem).AlignUp(HEAP_ALIGNMENT) + rem;
				rva = (rva - rem).AlignUp(HEAP_ALIGNMENT) + rem;
				...
			}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions