Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Another instant segfault when performing Bun.build() on a codebase with plugins. #14106

Closed
l1mey112 opened this issue Sep 23, 2024 · 1 comment
Labels
crash An issue that could cause a crash linux An issue that occurs on Linux

Comments

@l1mey112
Copy link

How can we reproduce the crash?

Clone the repository randomx.js at commit hash b76bb84. Then perform a simple bun build pointing at the library root, after running make.

await Bun.build({
	entrypoints: ['src/index.ts'],
	outdir: 'dist',
	plugins: [binayloader],
})

Keep in mind, make is needed to create the WASM files. You will need a simple clang installation, with the WABT and Binaryen toolchains installed.

This is similar to #14037 , but now using a plugin to create a module using contents instead of exports as that causes the build to just output nothing. The plugin below is being exported to then be called in scripts/build.ts

#!/usr/bin/env bun

import { plugin, type BunPlugin } from "bun"

export const binayloader: BunPlugin = {
	name: "binaryloader",
	async setup(build) {
		// create a toBinary module, one per build
		build.onLoad({ filter: /^__toBinary$/ }, async (args) => {
			return {
				contents: `export default /* @__PURE__ */ (() => {
					var table = new Uint8Array(128);
					for (var i = 0; i < 64; i++) table[i < 26 ? i + 65 : i < 52 ? i + 71 : i < 62 ? i - 4 : i * 4 - 205] = i;
					return (base64) => {
						var n = base64.length, bytes = new Uint8Array((n - (base64[n - 1] == "=") - (base64[n - 2] == "=")) * 3 / 4 | 0);
						for (var i2 = 0, j = 0; i2 < n; ) {
							var c0 = table[base64.charCodeAt(i2++)], c1 = table[base64.charCodeAt(i2++)];
							var c2 = table[base64.charCodeAt(i2++)], c3 = table[base64.charCodeAt(i2++)];
							bytes[j++] = c0 << 2 | c1 >> 4;
							bytes[j++] = c1 << 4 | c2 >> 2;
							bytes[j++] = c2 << 6 | c3;
						}
						return bytes;
					};
				})();`,
			}
		})

		build.onLoad({ filter: /\.(wasm)$/ }, async (args) => {
			const buffer = await Bun.file(args.path).arrayBuffer()

			/* return {
				exports: { default: new Uint8Array(buffer) },
				loader: "object",
			} */
			return {
				contents: `import __toBinary from "__toBinary";
					export default __toBinary("${Buffer.from(buffer).toString('base64')}");`,
			}
		})
	},
}

await plugin(binayloader)

Relevant log output

No response

Stack Trace (bun.report)

Bun v1.1.29 (6d43b36) on linux x86_64 [AutoCommand]

Segmentation fault at address 0x00000004

Features: jsc, bunfig, tsconfig

@l1mey112 l1mey112 added the crash An issue that could cause a crash label Sep 23, 2024
@github-actions github-actions bot added the linux An issue that occurs on Linux label Sep 23, 2024
@Jarred-Sumner
Copy link
Collaborator

Jarred-Sumner commented Sep 23, 2024

This is a duplicate of #14037, let's track it there.

@Jarred-Sumner Jarred-Sumner closed this as not planned Won't fix, can't repro, duplicate, stale Sep 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
crash An issue that could cause a crash linux An issue that occurs on Linux
Projects
None yet
Development

No branches or pull requests

2 participants