Skip to content

Commit

Permalink
Fix double closing of handle when loading compressed assembly in sing…
Browse files Browse the repository at this point in the history
…le-file (dotnet#113002)
  • Loading branch information
elinor-fung authored Feb 28, 2025
1 parent bb5f473 commit 04538da
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions src/coreclr/vm/peimagelayout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -710,7 +710,7 @@ FlatImageLayout::FlatImageLayout(PEImage* pOwner)
if (anonMap == NULL)
ThrowLastError();

LPVOID anonView = CLRMapViewOfFile(anonMap, FILE_MAP_READ | FILE_MAP_WRITE, 0, 0, 0);
CLRMapViewHolder anonView = CLRMapViewOfFile(anonMap, FILE_MAP_READ | FILE_MAP_WRITE, 0, 0, 0);
if (anonView == NULL)
ThrowLastError();

Expand All @@ -719,7 +719,7 @@ FlatImageLayout::FlatImageLayout(PEImage* pOwner)
PAL_ZStream zStream;
zStream.nextIn = (uint8_t*)addr;
zStream.availIn = (uint32_t)size;
zStream.nextOut = (uint8_t*)anonView;
zStream.nextOut = (uint8_t*)(void*)anonView;
zStream.availOut = (uint32_t)uncompressedSize;

// we match the compression side here. 15 is the window sise, negative means no zlib header.
Expand All @@ -743,9 +743,8 @@ FlatImageLayout::FlatImageLayout(PEImage* pOwner)
addr = anonView;
size = uncompressedSize;
// Replace file handles with the handles to anonymous map. This will release the handles to the original view and map.
m_FileView.Assign(anonView);
m_FileMap.Assign(anonMap);

m_FileView.Assign(anonView.Extract());
m_FileMap.Assign(anonMap.Extract());
#else
_ASSERTE(!"Failure extracting contents of the application bundle. Compressed files used with a standalone (not singlefile) apphost.");
ThrowHR(E_FAIL); // we don't have any indication of what kind of failure. Possibly a corrupt image.
Expand Down

0 comments on commit 04538da

Please sign in to comment.