Skip to content

Commit

Permalink
Fix div-by-zero introduced in #65926 (#66035)
Browse files Browse the repository at this point in the history
  • Loading branch information
EgorBo committed Mar 2, 2022
1 parent a7a4ed9 commit 96d7d90
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/coreclr/vm/eehash.inl
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ BOOL EEHashTableBase<KeyType, Helper, bDefaultCopyIsDeep>::Init(DWORD dwNumBucke
m_pVolatileBucketTable->m_pBuckets++;
m_pVolatileBucketTable->m_dwNumBuckets = dwNumBuckets;
#ifdef TARGET_64BIT
m_pVolatileBucketTable->m_dwNumBucketsMul = GetFastModMultiplier(dwNumBuckets);
m_pVolatileBucketTable->m_dwNumBucketsMul = dwNumBuckets == 0 ? 0 : GetFastModMultiplier(dwNumBuckets);
#endif

m_Heap = pHeap;
Expand Down Expand Up @@ -786,7 +786,7 @@ BOOL EEHashTableBase<KeyType, Helper, bDefaultCopyIsDeep>::GrowHashTable()
pNewBucketTable->m_pBuckets = pNewBuckets;
pNewBucketTable->m_dwNumBuckets = dwNewNumBuckets;
#ifdef TARGET_64BIT
pNewBucketTable->m_dwNumBucketsMul = GetFastModMultiplier(dwNewNumBuckets);
pNewBucketTable->m_dwNumBucketsMul = dwNewNumBuckets == 0 ? 0 : GetFastModMultiplier(dwNewNumBuckets);
#endif

// Add old table to the to free list. Note that the SyncClean thing will only
Expand Down
5 changes: 4 additions & 1 deletion src/coreclr/vm/util.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1017,7 +1017,10 @@ inline UINT64 GetFastModMultiplier(UINT32 divisor)

inline UINT32 FastMod(UINT32 value, UINT32 divisor, UINT64 multiplier)
{
return (UINT32)(((((multiplier * value) >> 32) + 1) * divisor) >> 32);
_ASSERTE(divisor <= INT_MAX);
UINT32 highbits = (UINT32)(((((multiplier * value) >> 32) + 1) * divisor) >> 32);
_ASSERTE(highbits == value % divisor);
return highbits;
}
#endif

Expand Down

0 comments on commit 96d7d90

Please sign in to comment.