Skip to content

Commit 96d7d90

Browse files
authored
Fix div-by-zero introduced in #65926 (#66035)
1 parent a7a4ed9 commit 96d7d90

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

src/coreclr/vm/eehash.inl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ BOOL EEHashTableBase<KeyType, Helper, bDefaultCopyIsDeep>::Init(DWORD dwNumBucke
198198
m_pVolatileBucketTable->m_pBuckets++;
199199
m_pVolatileBucketTable->m_dwNumBuckets = dwNumBuckets;
200200
#ifdef TARGET_64BIT
201-
m_pVolatileBucketTable->m_dwNumBucketsMul = GetFastModMultiplier(dwNumBuckets);
201+
m_pVolatileBucketTable->m_dwNumBucketsMul = dwNumBuckets == 0 ? 0 : GetFastModMultiplier(dwNumBuckets);
202202
#endif
203203

204204
m_Heap = pHeap;
@@ -786,7 +786,7 @@ BOOL EEHashTableBase<KeyType, Helper, bDefaultCopyIsDeep>::GrowHashTable()
786786
pNewBucketTable->m_pBuckets = pNewBuckets;
787787
pNewBucketTable->m_dwNumBuckets = dwNewNumBuckets;
788788
#ifdef TARGET_64BIT
789-
pNewBucketTable->m_dwNumBucketsMul = GetFastModMultiplier(dwNewNumBuckets);
789+
pNewBucketTable->m_dwNumBucketsMul = dwNewNumBuckets == 0 ? 0 : GetFastModMultiplier(dwNewNumBuckets);
790790
#endif
791791

792792
// Add old table to the to free list. Note that the SyncClean thing will only

src/coreclr/vm/util.hpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1017,7 +1017,10 @@ inline UINT64 GetFastModMultiplier(UINT32 divisor)
10171017

10181018
inline UINT32 FastMod(UINT32 value, UINT32 divisor, UINT64 multiplier)
10191019
{
1020-
return (UINT32)(((((multiplier * value) >> 32) + 1) * divisor) >> 32);
1020+
_ASSERTE(divisor <= INT_MAX);
1021+
UINT32 highbits = (UINT32)(((((multiplier * value) >> 32) + 1) * divisor) >> 32);
1022+
_ASSERTE(highbits == value % divisor);
1023+
return highbits;
10211024
}
10221025
#endif
10231026

0 commit comments

Comments
 (0)