Skip to content
This repository has been archived by the owner on Jan 23, 2023. It is now read-only.

Commit

Permalink
Allow PEImageLayout to be loadable for R2R images loaded from streams. (
Browse files Browse the repository at this point in the history
#25159)

* Allow PEImageLayout to be loadable for R2R images loaded from streams.

* Add regression test coverage

* Change CheckILOnly to return true for R2R images (similar to the ILOnly API)

* Early out for R2R images

* Remove R2R check
  • Loading branch information
Fadi Hanna authored Jun 18, 2019
1 parent d6bec4a commit 2b85852
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/utilcode/pedecoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ CHECK PEDecoder::CheckFormat() const
{
CHECK(CheckCorHeader());

if (IsILOnly() && !HasReadyToRunHeader())
if (IsILOnly())
CHECK(CheckILOnly());

if (HasNativeHeader())
Expand Down Expand Up @@ -1406,6 +1406,12 @@ CHECK PEDecoder::CheckILOnly() const

CHECK(CheckCorHeader());

if (HasReadyToRunHeader())
{
// Pretend R2R images are IL-only
const_cast<PEDecoder *>(this)->m_flags |= FLAG_IL_ONLY_CHECKED;
CHECK_OK;
}

// Allow only verifiable directories.

Expand Down
12 changes: 12 additions & 0 deletions tests/src/readytorun/tests/main.cs
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,16 @@ static void RVAFieldTest()
Assert.AreEqual(value[i], (byte)(9 - i));
}

static void TestLoadR2RImageFromByteArray()
{
Assembly assembly1 = typeof(Program).Assembly;

byte[] array = File.ReadAllBytes(assembly1.Location);
Assembly assembly2 = Assembly.Load(array);

Assert.AreEqual(assembly2.FullName, assembly1.FullName);
}

static void RunAllTests()
{
TestVirtualMethodCalls();
Expand Down Expand Up @@ -479,6 +489,8 @@ static void RunAllTests()
GenericLdtokenFieldsTest();

RVAFieldTest();

TestLoadR2RImageFromByteArray();
}

static int Main()
Expand Down

0 comments on commit 2b85852

Please sign in to comment.