Skip to content

Fix power-of-two integer hash collisions - #1720

Merged
bnoordhuis merged 1 commit into
quickjs-ng:masterfrom
bnoordhuis:fix1717
Sep 9, 2026
Merged

bnoordhuis merged 1 commit into
quickjs-ng:masterfrom
bnoordhuis:fix1717

Conversation

@bnoordhuis

Copy link
Copy Markdown
Contributor

Don't use integer values verbatim but hash them first by multiplicating them with a magic value, like we do elsewhere. Most of the randomness ends up in the high bits so use those to index into the hash table, i.e., right-shift the hashed value.

Fixes: #1717

Don't use integer values verbatim but hash them first by multiplicating
them with a magic value, like we do elsewhere. Most of the randomness
ends up in the high bits so use those to index into the hash table,
i.e., right-shift the hashed value.

Fixes: quickjs-ng#1717
Comment thread cutils.h

static inline uint64_t hash64(uint64_t a)
{
return a * 0x61c8864680b583ebULL;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just curious: how is this number picked? By fair dice roll? 😅

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's a comment a few lines up that explains it, it's based on the golden ratio. hash32 uses the same constant, except truncated to 32 bits.

@bnoordhuis
bnoordhuis merged commit cad311e into quickjs-ng:master Sep 9, 2026
128 checks passed
@bnoordhuis
bnoordhuis deleted the fix1717 branch September 9, 2026 13:30
social4hyq pushed a commit to social4hyq/homebrew-core that referenced this pull request Sep 20, 2026
quickjs-ng 0.17.0

Created-by: HarmonybrewBot
Commit-by: HarmonybrewBot
Merged-by: HarmonybrewBot
Description: Created by `brew bump`

---

Created with `brew bump-formula-pr`.<details>
  <summary>release notes</summary>
  <pre>## What's Changed
* update projects.md to include scriptc project reference (from the Ver… by @lukasMega in quickjs-ng/quickjs#1677
* Fixes segfault from #1661 by @sr5434 in quickjs-ng/quickjs#1675
* docs: add Qbs to projects by @ABBAPOH in quickjs-ng/quickjs#1685
* Add Big Endian architecture support instructions by @saghul in quickjs-ng/quickjs#1681
* Conditional BUILD_DIR by @kapouer in quickjs-ng/quickjs#1686
* Fix String.prototype.normalize() crash from #1683 by @sr5434 in quickjs-ng/quickjs#1688
* Fix reference count bug in Promise.withResolvers by @bnoordhuis in quickjs-ng/quickjs#1692
* Enable test262 host-gc-required feature by @bnoordhuis in quickjs-ng/quickjs#1696
* docs: add Vayu to projects by @athrvk in quickjs-ng/quickjs#1702
* Use mirror for Alpine GHA by @bnoordhuis in quickjs-ng/quickjs#1705
* Fix Iterator.from GetIteratorDirect handling by @jiang1997 in quickjs-ng/quickjs#1706
* Link against libm unconditionally on Unices by @bnoordhuis in quickjs-ng/quickjs#1699
* Fix out-of-bound read in JS_NewTypedArray by @bnoordhuis in quickjs-ng/quickjs#1704
* Preserve old interrupt handler in std.evalScript by @bnoordhuis in quickjs-ng/quickjs#1707
* fix: correct int/int32_t pointer mismatches for -Wincompatible-pointer-types by @SomSamantray in quickjs-ng/quickjs#1657
* Fix JS_FreeCStringUTF16 on slice strings by @bnoordhuis in quickjs-ng/quickjs#1709
* Add react-native-quickjs project to documentation by @saghul in quickjs-ng/quickjs#1710
* Move JSClass out of quickjs.h by @bnoordhuis in quickjs-ng/quickjs#1713
* Optimize JS_DeleteGlobalVar by @bnoordhuis in quickjs-ng/quickjs#1714
* Throw error when converting BigIntArray to Int8Array (#1690) by @sr5434 in quickjs-ng/quickjs#1694
* Fix power-of-two integer hash collisions by @bnoordhuis in quickjs-ng/quickjs#1720
* Store constant atoms more compactly in wire format by @bnoordhuis in quickjs-ng/quickjs#1719
* Prevent Object.preventExtensions when a TypedArray has a resizable ArrayBuffer by @sr5434 in quickjs-ng/quickjs#1695
* Make DOMException a bit more conformant by @goffrie in quickjs-ng/quickjs#1721
* Fix TypedArray.prototype.at() to handle resized ArrayBuffer correctly by @sr5434 in quickjs-ng/quickjs#1718
* Fix JS_SetMemoryLimit byte accounting on WASI by @josefguenther in quickjs-ng/quickjs#1711
* Fix(wasi): enable configurable stack overflow protection by @aayush-kapoor in quickjs-ng/quickjs#1700
* Use a bigger initial atom hash table by @bnoordhuis in quickjs-ng/quickjs#1723
* Add private symbols by @bnoordhuis in quickjs-ng/quickjs#1725
* Peephole-optimize negation + conditional jump by @bnoordhuis in quickjs-ng/quickjs#1726
* Check for property deletion when accessing in `with` by @sr5434 in quickjs-ng/quickjs#1722

## New Contributors
* @lukasMega made their first contribution in quickjs-ng/quickjs#1677
* @kapouer made their first contribution in quickjs-ng/quickjs#1686
* @athrvk made their first contribution in quickjs-ng/quickjs#1702
* @SomSamantray made their first contribution in quickjs-ng/quickjs#1657
* @goffrie made their first contribution in quickjs-ng/quickjs#1721
* @josefguenther made their first contribution in quickjs-ng/quickjs#1711
* @aayush-kapoor made their first contribution in quickjs-ng/quickjs#1700

**Full Changelog**: https://github.com/quickjs-ng/quickjs/compare/v0.16.2...v0.17.0</pre>
  <p>View the full release notes at <a href="https://github.com/quickjs-ng/quickjs/releases/tag/v0.17.0">https://github.com/quickjs-ng/quickjs/releases/tag/v0.17.0</a>.</p>
</details>
<hr>

See merge request: Harmonybrew/homebrew-core!20596
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Property lookup can degrade with integer atom collisions

2 participants