Skip to content

Fix crash in Bun.build with many conditions#30514

Closed
robobun wants to merge 1 commit into
mainfrom
farm/358a149b/fix-esm-conditions-capacity
Closed

Fix crash in Bun.build with many conditions#30514
robobun wants to merge 1 commit into
mainfrom
farm/358a149b/fix-esm-conditions-capacity

Conversation

@robobun

@robobun robobun commented May 11, 2026

Copy link
Copy Markdown
Collaborator

What does this PR do?

Fixes an operator precedence bug in ESMConditions.init that caused a debug assertion failure (and potential memory corruption in release) when passing several conditions to Bun.build().

The expression:

defaults.len + 2 + if (allow_addons) 1 else 0 + conditions.len

parses as:

defaults.len + 2 + (if (allow_addons) 1 else (0 + conditions.len))

So when allow_addons is true (the default), conditions.len is dropped from the reserved capacity and subsequent putAssumeCapacity calls overflow the map.

How did you verify your code works?

Added a regression test that passes 10 conditions to Bun.build(). Before this fix it triggers reached unreachable code in MultiArrayList.addOneAssumeCapacity; after the fix it builds successfully.

Found by Fuzzilli (fingerprint fdba7e39f969672c).

The expression 'if (allow_addons) 1 else 0 + conditions.len' parses as
'if (allow_addons) 1 else (0 + conditions.len)', so when allow_addons
is true (the default), conditions.len is dropped from the reserved
capacity, causing putAssumeCapacity to overflow when enough conditions
are passed to Bun.build().
@robobun

robobun commented May 11, 2026

Copy link
Copy Markdown
Collaborator Author
Updated 1:09 PM PT - May 11th, 2026

@robobun, your commit 0c7a84d has 1 failures in Build #53446 (All Failures):


🧪   To try this PR locally:

bunx bun-pr 30514

That installs a local version of the PR into your bun-30514 executable, so you can run:

bun-30514 --bun

@github-actions

Copy link
Copy Markdown
Contributor

This PR may be a duplicate of:

  1. Fix crash in Bun.build with many conditions #30466 - Also fixes the crash in Bun.build with many conditions by correcting the ESMConditions.init capacity calculation in src/bundler/options.zig

🤖 Generated with Claude Code

@robobun

robobun commented May 11, 2026

Copy link
Copy Markdown
Collaborator Author

Duplicate of #30466.

@robobun robobun closed this May 11, 2026
@robobun robobun deleted the farm/358a149b/fix-esm-conditions-capacity branch May 11, 2026 20:09
@coderabbitai

coderabbitai Bot commented May 11, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: c03e4bbe-f7bf-4f09-aec1-ba33e5eb9b7d

📥 Commits

Reviewing files that changed from the base of the PR and between 4c0a5a7 and 0c7a84d.

📒 Files selected for processing (2)
  • src/bundler/options.zig
  • test/bundler/bun-build-api.test.ts

Disabled knowledge base sources:

  • Linear integration is disabled

You can enable these sources in your CodeRabbit configuration.


Walkthrough

ESMConditions capacity computation is simplified to use @intFromBool(allow_addons) instead of a conditional expression. A regression test verifies the build succeeds with multiple conditions.

Changes

Bundler Conditions Capacity Fix

Layer / File(s) Summary
ESMConditions Capacity Simplification
src/bundler/options.zig
Capacity computation for condition maps uses @intFromBool(allow_addons) instead of if (allow_addons) 1 else 0.
Many Conditions Regression Test
test/bundler/bun-build-api.test.ts
Concurrent test verifies build succeeds when provided ten custom conditions (c1–c10).

Comment @coderabbitai help to get the list of available commands and usage tips.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant