mirror of
https://github.com/oven-sh/bun
synced 2026-02-12 03:48:56 +00:00
fix(brotli): protect and unprotect buffer values (#12829)
This commit is contained in:
@@ -101,11 +101,6 @@ pub fn runExitCallbacks() void {
|
||||
on_exit_callbacks.items.len = 0;
|
||||
}
|
||||
|
||||
/// Flushes stdout and stderr and exits with the given code.
|
||||
pub fn exit(code: u8) noreturn {
|
||||
exitWide(@as(u32, code));
|
||||
}
|
||||
|
||||
var is_exiting = std.atomic.Value(bool).init(false);
|
||||
export fn bun_is_exiting() c_int {
|
||||
return @intFromBool(isExiting());
|
||||
@@ -114,7 +109,8 @@ pub fn isExiting() bool {
|
||||
return is_exiting.load(.monotonic);
|
||||
}
|
||||
|
||||
pub fn exitWide(code: u32) noreturn {
|
||||
/// Flushes stdout and stderr (in exit/quick_exit callback) and exits with the given code.
|
||||
pub fn exit(code: u32) noreturn {
|
||||
is_exiting.store(true, .monotonic);
|
||||
|
||||
if (comptime Environment.isMac) {
|
||||
|
||||
@@ -272,6 +272,9 @@ pub const BrotliEncoder = struct {
|
||||
{
|
||||
this.input_lock.lock();
|
||||
defer this.input_lock.unlock();
|
||||
|
||||
// need to protect because no longer on the stack. unprotected in FreeList.deinit
|
||||
input_to_queue.protect();
|
||||
this.input.writeItem(input_to_queue) catch bun.outOfMemory();
|
||||
}
|
||||
JSC.WorkPool.schedule(&task.task);
|
||||
@@ -314,6 +317,8 @@ pub const BrotliEncoder = struct {
|
||||
this.input_lock.lock();
|
||||
defer this.input_lock.unlock();
|
||||
|
||||
// need to protect because no longer on the stack. unprotected in FreeList.deinit
|
||||
input_to_queue.protect();
|
||||
this.input.writeItem(input_to_queue) catch bun.outOfMemory();
|
||||
}
|
||||
task.run();
|
||||
@@ -489,6 +494,8 @@ pub const BrotliDecoder = struct {
|
||||
this.input_lock.lock();
|
||||
defer this.input_lock.unlock();
|
||||
|
||||
// need to protect because no longer on the stack. unprotected in FreeList.deinit
|
||||
input_to_queue.protect();
|
||||
this.input.writeItem(input_to_queue) catch bun.outOfMemory();
|
||||
}
|
||||
JSC.WorkPool.schedule(&task.task);
|
||||
@@ -531,6 +538,8 @@ pub const BrotliDecoder = struct {
|
||||
this.input_lock.lock();
|
||||
defer this.input_lock.unlock();
|
||||
|
||||
// need to protect because no longer on the stack. unprotected in FreeList.deinit
|
||||
input_to_queue.protect();
|
||||
this.input.writeItem(input_to_queue) catch bun.outOfMemory();
|
||||
}
|
||||
task.run();
|
||||
|
||||
@@ -173,101 +173,4 @@ pub extern fn JSRemoteInspectorSetLogToSystemConsole(enabled: bool) void;
|
||||
pub extern fn JSRemoteInspectorGetInspectionEnabledByDefault(void) bool;
|
||||
pub extern fn JSRemoteInspectorSetInspectionEnabledByDefault(enabled: bool) void;
|
||||
|
||||
// -- Manual --
|
||||
|
||||
const size_t = usize;
|
||||
|
||||
pub const CellType = enum(u8) {
|
||||
pub const LastMaybeFalsyCellPrimitive = 2;
|
||||
pub const LastJSCObjectType = 73;
|
||||
|
||||
CellType = 0,
|
||||
StringType = 1,
|
||||
HeapBigIntType = 2,
|
||||
|
||||
SymbolType = 3,
|
||||
GetterSetterType = 4,
|
||||
CustomGetterSetterType = 5,
|
||||
APIValueWrapperType = 6,
|
||||
NativeExecutableType = 7,
|
||||
ProgramExecutableType = 8,
|
||||
ModuleProgramExecutableType = 9,
|
||||
EvalExecutableType = 10,
|
||||
FunctionExecutableType = 11,
|
||||
UnlinkedFunctionExecutableType = 12,
|
||||
UnlinkedProgramCodeBlockType = 13,
|
||||
UnlinkedModuleProgramCodeBlockType = 14,
|
||||
UnlinkedEvalCodeBlockType = 15,
|
||||
UnlinkedFunctionCodeBlockType = 16,
|
||||
CodeBlockType = 17,
|
||||
JSImmutableButterflyType = 18,
|
||||
JSSourceCodeType = 19,
|
||||
JSScriptFetcherType = 20,
|
||||
JSScriptFetchParametersType = 21,
|
||||
ObjectType = 22,
|
||||
FinalObjectType = 23,
|
||||
JSCalleeType = 24,
|
||||
JSFunctionType = 25,
|
||||
InternalFunctionType = 26,
|
||||
NullSetterFunctionType = 27,
|
||||
BooleanObjectType = 28,
|
||||
NumberObjectType = 29,
|
||||
ErrorInstanceType = 30,
|
||||
GlobalProxyType = 31,
|
||||
DirectArgumentsType = 32,
|
||||
ScopedArgumentsType = 33,
|
||||
ClonedArgumentsType = 34,
|
||||
ArrayType = 35,
|
||||
DerivedArrayType = 36,
|
||||
ArrayBufferType = 37,
|
||||
Int8ArrayType = 38,
|
||||
Uint8ArrayType = 39,
|
||||
Uint8ClampedArrayType = 40,
|
||||
Int16ArrayType = 41,
|
||||
Uint16ArrayType = 42,
|
||||
Int32ArrayType = 43,
|
||||
Uint32ArrayType = 44,
|
||||
Float32ArrayType = 45,
|
||||
Float64ArrayType = 46,
|
||||
BigInt64ArrayType = 47,
|
||||
BigUint64ArrayType = 48,
|
||||
DataViewType = 49,
|
||||
GlobalObjectType = 50,
|
||||
GlobalLexicalEnvironmentType = 51,
|
||||
LexicalEnvironmentType = 52,
|
||||
ModuleEnvironmentType = 53,
|
||||
StrictEvalActivationType = 54,
|
||||
WithScopeType = 55,
|
||||
ModuleNamespaceObjectType = 56,
|
||||
RegExpObjectType = 57,
|
||||
JSDateType = 58,
|
||||
ProxyObjectType = 59,
|
||||
JSGeneratorType = 60,
|
||||
JSAsyncGeneratorType = 61,
|
||||
JSArrayIteratorType = 62,
|
||||
JSMapIteratorType = 63,
|
||||
JSSetIteratorType = 64,
|
||||
JSStringIteratorType = 65,
|
||||
JSPromiseType = 66,
|
||||
JSMapType = 67,
|
||||
JSSetType = 68,
|
||||
JSWeakMapType = 69,
|
||||
JSWeakSetType = 70,
|
||||
WebAssemblyModuleType = 71,
|
||||
WebAssemblyInstanceType = 72,
|
||||
WebAssemblyGCObjectType = 73,
|
||||
StringObjectType = 74,
|
||||
DerivedStringObjectType = 75,
|
||||
|
||||
MaxJSType = 255,
|
||||
_,
|
||||
|
||||
pub fn isString(this: CellType) bool {
|
||||
return switch (this) {
|
||||
.StringType => true,
|
||||
else => false,
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
pub extern "c" fn JSObjectGetProxyTarget(JSObjectRef) JSObjectRef;
|
||||
|
||||
@@ -2330,7 +2330,7 @@ pub const win32 = struct {
|
||||
if (exit_code == watcher_reload_exit) {
|
||||
continue;
|
||||
} else {
|
||||
Global.exitWide(exit_code);
|
||||
Global.exit(exit_code);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -177,7 +177,7 @@ pub const Run = struct {
|
||||
// JSC initialization costs 1-3ms. We skip this if we know it's a shell script.
|
||||
if (strings.endsWithComptime(entry_path, ".sh")) {
|
||||
const exit_code = try bootBunShell(ctx, entry_path);
|
||||
Global.exitWide(exit_code);
|
||||
Global.exit(exit_code);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -50,7 +50,7 @@ pub const ExecCommand = struct {
|
||||
// Output.flush();
|
||||
// }
|
||||
|
||||
Global.exitWide(code);
|
||||
Global.exit(code);
|
||||
// }
|
||||
}
|
||||
};
|
||||
|
||||
@@ -328,7 +328,7 @@ pub const RunCommand = struct {
|
||||
Output.flush();
|
||||
}
|
||||
|
||||
Global.exitWide(code);
|
||||
Global.exit(code);
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
@@ -1105,7 +1105,7 @@ pub const TestCommand = struct {
|
||||
if (reporter.summary.fail > 0 or (coverage.enabled and coverage.fractions.failing and coverage.fail_on_low_coverage)) {
|
||||
Global.exit(1);
|
||||
} else if (reporter.jest.unhandled_errors_between_tests > 0) {
|
||||
Global.exitWide(@intCast(reporter.jest.unhandled_errors_between_tests));
|
||||
Global.exit(reporter.jest.unhandled_errors_between_tests);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user