Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@ updates:
directory: "/"
schedule:
interval: "daily"
cooldown:
default-days: 7
- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "daily"
cooldown:
default-days: 7
24 changes: 24 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,30 @@ jobs:
- name: Build and test
run: rake -m test:run:serial

Cosmopolitan:
runs-on: ubuntu-24.04
timeout-minutes: 15
steps:
- name: "Checkout ${{ github.ref }} ( ${{ github.sha }} )"
uses: actions/checkout@v6
- name: Ruby version
run: ruby -v
- name: Cache cosmocc
uses: actions/cache@v4
id: cache-cosmocc
with:
path: ~/cosmo
key: cosmocc-${{ runner.os }}-20260104
- name: Install cosmocc
if: steps.cache-cosmocc.outputs.cache-hit != 'true'
run: |
mkdir -p ~/cosmo && cd ~/cosmo
wget https://cosmo.zip/pub/cosmocc/cosmocc.zip
unzip cosmocc.zip
- name: Build and test
run: |
COSMO_ROOT=~/cosmo rake -m test:run:serial MRUBY_CONFIG=cosmopolitan

Windows-VC:
runs-on: windows-2022
timeout-minutes: 10
Expand Down
3 changes: 2 additions & 1 deletion include/mruby.h
Original file line number Diff line number Diff line change
Expand Up @@ -1571,7 +1571,8 @@ MRB_API mrb_value mrb_fiber_alive_p(mrb_state *mrb, mrb_value fib);
MRB_API void mrb_stack_extend(mrb_state*, mrb_int);

/* temporary memory allocation, only effective while GC arena is kept */
MRB_API void* mrb_alloca(mrb_state *mrb, size_t);
MRB_API void* mrb_temp_alloc(mrb_state *mrb, size_t);
#define mrb_alloca(mrb, size) mrb_temp_alloc(mrb, size) /* for compatibility */

MRB_API void mrb_state_atexit(mrb_state *mrb, mrb_atexit_func func);

Expand Down
19 changes: 18 additions & 1 deletion mrbgems/mruby-bigint/core/bigint.c
Original file line number Diff line number Diff line change
Expand Up @@ -3417,6 +3417,10 @@ mrb_bint_cmp(mrb_state *mrb, mrb_value x, mrb_value y)
return mpz_cmp(ctx, &a, &b);
}

/* Maximum bits for power result to prevent resource exhaustion */
/* 1 million bits = ~125KB per bigint, ~300,000 decimal digits */
#define MRB_BIGINT_POW_MAX_BITS 1000000

mrb_value
mrb_bint_pow(mrb_state *mrb, mrb_value x, mrb_value y)
{
Expand All @@ -3432,9 +3436,22 @@ mrb_bint_pow(mrb_state *mrb, mrb_value x, mrb_value y)
mrb_raisef(mrb, E_TYPE_ERROR, "%Y cannot be convert to integer", y);
}

mrb_int exp = mrb_integer(y);
if (exp < 0) {
mrb_raise(mrb, E_ARGUMENT_ERROR, "negative exponent");
}

/* Check if result would be too large */
/* result_bits ≈ base_bits * exp */
size_t base_bits = mpz_bits(&a);
if (base_bits == 0) base_bits = 1; /* handle 0 and 1 */
if (exp > 0 && (size_t)exp > MRB_BIGINT_POW_MAX_BITS / base_bits) {
mrb_raise(mrb, E_RANGE_ERROR, "exponent too large");
}

mpz_t z;
MPZ_CTX_INIT(mrb, ctx, pool);
mpz_pow(ctx, &z, &a, mrb_integer(y));
mpz_pow(ctx, &z, &a, exp);

struct RBigint *b = bint_new(ctx, &z);
return mrb_obj_value(b);
Expand Down
1 change: 1 addition & 0 deletions mrbgems/mruby-bin-mirb/tools/mirb/mirb_term.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include <unistd.h>
#include <termios.h>
#include <sys/ioctl.h>
#include <sys/select.h>
#include <errno.h>

/*
Expand Down
3 changes: 3 additions & 0 deletions mrbgems/mruby-compiler/core/codegen.c
Original file line number Diff line number Diff line change
Expand Up @@ -1242,8 +1242,11 @@ static void
realloc_pool_str(codegen_scope *s, mrb_irep_pool *p, mrb_int len)
{
char *str;
mrb_int olen = p->tt >> 2; /* original length */
if ((p->tt & 3) == IREP_TT_SSTR) { /* Check if it's a shared/static string */
const char *old = p->u.str;
str = (char*)mrbc_malloc(len+1); /* Allocate new memory if it was shared */
memcpy(str, old, olen); /* Copy original content */
}
else { /* It's already a heap-allocated string */
str = (char*)p->u.str;
Expand Down
4 changes: 4 additions & 0 deletions mrbgems/mruby-compiler/core/parse.y
Original file line number Diff line number Diff line change
Expand Up @@ -4562,11 +4562,15 @@ f_arglist : f_arglist_paren

f_label : tIDENTIFIER tLABEL_TAG
{
$$ = $1;
local_nest(p);
p->lstate = EXPR_ARG; /* make newlines significant after label */
}
| tNUMPARAM tLABEL_TAG
{
$$ = intern_numparam($1);
local_nest(p);
p->lstate = EXPR_ARG; /* make newlines significant after label */
}
;

Expand Down
Loading
Loading