Commit Graph

14098 Commits

Author SHA1 Message Date
dearblue 2d9ecc660e Fix property between ar_set() and ht_init().
If GC occurs in `mrb_realloc()` in `ht_init()` called from `ar_set()`, the following inconsistency occurs:
- If `h_ht_on()` is called before `mrb_realloc()`, `hash->hsh.ht` is referenced instead of `hash->hsh.ea` during GC.
- If the pointer is changed by `ea_adjust()` in `ar_set()`, `hash->hsh.ea` (`hash->hsh.ht`) is referenced in GC before the change.

These modifications can be resolved by changing the order of processing.

However, if a `NoMemoryError` exception is raised, it is presumed that the size of the "AR" will be exceeded and the unintended state will continue.
To prevent this, elements should be added after they have been converted to "HT".
2022-07-30 23:20:48 +09:00
Yukihiro "Matz" Matsumoto 9e38aa8948 Merge pull request #5761 from jbampton/fix-grammar
docs: fix grammar
2022-07-30 15:56:48 +09:00
Yukihiro "Matz" Matsumoto b77b8f4deb numeric.c (flo_ceil_floor): negate after converting integer to float.
Otherwise integer negate may overflow.
2022-07-30 09:08:42 +09:00
Yukihiro "Matz" Matsumoto 9d774bc011 numeric.c (flo_ceil_floor): return bigint if possible. 2022-07-30 09:08:02 +09:00
Yukihiro "Matz" Matsumoto eb392cb643 numeric.c (mrb_float_to_integer): check for RangeError.
Otherwise flo_to_i raises FloatDomainError instead.
2022-07-30 09:06:49 +09:00
Yukihiro "Matz" Matsumoto e4bcd8a96a numeric.c (mrb_float_to_integer): unify with flo_to_i(). 2022-07-30 09:05:21 +09:00
Yukihiro "Matz" Matsumoto 5af98f2088 numeric.c (flo_ceil_floor): add exact number check. 2022-07-30 09:01:24 +09:00
Yukihiro "Matz" Matsumoto aebf75fed4 bigint.c (mrb_bint_as_int): change overflow message.
From "integer too big" to "integer out of range" because the integer can
be too small if it's negative.
2022-07-30 08:58:30 +09:00
Yukihiro "Matz" Matsumoto b8d3bc0eae numeric.c: move FloatDomainError description to the sufficient place. 2022-07-30 08:46:06 +09:00
Yukihiro "Matz" Matsumoto 89b0c7d7ab complex.c (mrb_complex_to_i): return bigint if possible. 2022-07-30 08:44:15 +09:00
Yukihiro "Matz" Matsumoto 273ca4d4f6 tasks/toolchains/gcc.rake: remove -lm on Windows; #5757 2022-07-30 07:33:45 +09:00
Yukihiro "Matz" Matsumoto 6da34fa735 numeric.c (int_div): add checks for division by zero. 2022-07-29 17:48:02 +09:00
John Bampton 9521e4e974 docs: fix grammar 2022-07-29 16:30:46 +10:00
Yukihiro "Matz" Matsumoto 387f383eeb bigint.c (mrb_sizeinbase): cast to remove a signedness warning. 2022-07-29 10:26:04 +09:00
Yukihiro "Matz" Matsumoto 5df3f8221d bigint.c (lzb): check x==0 before calling clz().
In theory, we should not call lzb() with 0, and we assume checks are
done before calling it. But we got a report that we call lzb(0) in some
use-case. We could not reproduce the issue, so we add this guard.
2022-07-29 10:24:41 +09:00
Yukihiro "Matz" Matsumoto 64ea7f0930 doc/guides/link.md: fixed typo. 2022-07-29 10:24:41 +09:00
Yukihiro "Matz" Matsumoto 23cb2a73ff bigint.c (mpz_move): reduce copying of digits arrays. 2022-07-29 10:24:41 +09:00
Yukihiro "Matz" Matsumoto dcf9e32870 Merge pull request #5759 from jbampton/lint-modified-files
Super-Linter: Lint modified files only
2022-07-29 10:24:01 +09:00
John Bampton 9ddc6c1915 Super-Linter: Lint modified files only
Following the basic example shown here

https://github.com/github/super-linter#example-connecting-github-action-workflow
2022-07-29 09:19:28 +10:00
Yukihiro "Matz" Matsumoto 33b11daca7 Merge pull request #5758 from jbampton/pre-commit-autoupdate
pre-commit autoupdate
2022-07-29 07:43:59 +09:00
John Bampton 718547be2b pre-commit autoupdate
https://pre-commit.com/#pre-commit-autoupdate
2022-07-29 08:29:12 +10:00
Yukihiro "Matz" Matsumoto d0780c0525 vm.c: should cast bigint length to unsigned.
Otherwise length>127 would be considered as negative.
2022-07-28 15:21:32 +09:00
Yukihiro "Matz" Matsumoto de2ea3c389 bigint.c (udiv): avoid integer underflow. 2022-07-28 15:07:22 +09:00
Yukihiro "Matz" Matsumoto 9592b7e4ec mruby_proto_fuzzer.cpp: try to print the code before evaluating it. 2022-07-27 13:42:28 +09:00
Yukihiro "Matz" Matsumoto 4620485135 Merge pull request #5756 from mruby/dependabot/github_actions/github/super-linter-4.9.5
build(deps): bump github/super-linter from 4.9.4 to 4.9.5
2022-07-27 09:23:05 +09:00
dependabot[bot] a65f953356 build(deps): bump github/super-linter from 4.9.4 to 4.9.5
Bumps [github/super-linter](https://github.com/github/super-linter) from 4.9.4 to 4.9.5.
- [Release notes](https://github.com/github/super-linter/releases)
- [Changelog](https://github.com/github/super-linter/blob/main/docs/release-process.md)
- [Commits](https://github.com/github/super-linter/compare/v4.9.4...v4.9.5)

---
updated-dependencies:
- dependency-name: github/super-linter
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2022-07-26 14:09:39 +00:00
Yukihiro "Matz" Matsumoto 25a32ed681 bigint.c (ulshift,urshift): check uzero before actual shifting.
Bit-shifting zero always result in zero.
2022-07-26 15:06:06 +09:00
Yukihiro "Matz" Matsumoto 97b9bfc4fa bigint.c (mpz_init_set_str): move negative trick to mrb_bint_new_str().
It used to take negative base to generate negative value. But this weird
trick is now belong to the mruby API side.
2022-07-26 15:03:52 +09:00
Yukihiro "Matz" Matsumoto c2e4b82d84 codegen.c (new_litbint): remove surrounding braces.
It was to allow local variable declarations, but now we allow
declarations in the middle.
2022-07-26 13:55:54 +09:00
Yukihiro "Matz" Matsumoto 26ce85bd5d bigint.c (ucmp): fixed error with zero length zero value.
Big integers have two kind of zero values:

- digits in `p` array are all zeros
- length `sn` is zero

The old code crashed with the latter zero.
2022-07-26 00:13:15 +09:00
Yukihiro "Matz" Matsumoto e8ce82bf31 codegen.c (new_litbint): forgot else in a107b85. 2022-07-26 00:11:53 +09:00
Yukihiro "Matz" Matsumoto 3d1b5d2b06 Merge pull request #5754 from artichoke/lopopolo/class-name-use-after-free
Fix possible use after free in `mrb_class_find_path`
2022-07-25 15:41:07 +09:00
Yukihiro "Matz" Matsumoto c6bf4eaac0 codegen.c (new_litbint): renamed from new_litbn. 2022-07-25 15:33:43 +09:00
Yukihiro "Matz" Matsumoto a107b850eb codegen.c (new_bitbn): fixed wrong packing of integer radix. 2022-07-25 15:31:43 +09:00
Yukihiro "Matz" Matsumoto d2d105b589 bigint.c (mpz_get_int): should work with zero (i.e. y->p == NULL). 2022-07-25 14:54:41 +09:00
Yukihiro "Matz" Matsumoto 6a4c8e36b5 bigint.c (udiv): should trim remainder before bit shifting. 2022-07-25 14:54:41 +09:00
Yukihiro "Matz" Matsumoto e02e9ae434 bigint.c (mpz_mmod): should call mpz_clear() for internal mpz_t. 2022-07-25 14:54:41 +09:00
Yukihiro "Matz" Matsumoto 7d5475916c bigint.c (udiv): avoid out of bound access in division. 2022-07-25 14:54:40 +09:00
Yukihiro "Matz" Matsumoto 657263446e bigint.c: cosmetic changes (add spaces, etc.) 2022-07-25 14:54:40 +09:00
Yukihiro "Matz" Matsumoto 866ab88c94 mruby-os-memsize/memsize.c: add fall through comment. 2022-07-25 10:58:03 +09:00
Yukihiro "Matz" Matsumoto 13d909bd3c array.c: new configuration MRB_ARY_LENGTH_MAX.
The default value is 2**17 entries. If you want to avoid the limitation,
set this value to 0.
2022-07-25 10:58:02 +09:00
Yukihiro "Matz" Matsumoto c4cb416460 string.c: new configuration MRB_STR_LENGTH_MAX.
The default value is 1MB. If you want to avoid the limitation, set this
value to 0.
2022-07-25 10:58:02 +09:00
Yukihiro "Matz" Matsumoto 199758c0b9 bigint.c (mpz_sizeinbase): should return size_t instead of int.
`int` may overflow.
2022-07-25 10:58:02 +09:00
Ryan Lopopolo 547d465340 Fix possible use after free in mrb_class_find_path
`mrb_class_find_path` resolves a `char*` pointer to a class name string
by calling `mrb_class_name`. It then allocates a new string with
capacity 40 to copy that `char*` into.

https://github.com/mruby/mruby/blob/e04184185ab43b94980550e850d8813a415fa438/src/variable.c#L1111-L1112

`mrb_class_name` resolves the class name via `class_name_str`, which
returns an `mrb_value` with type tag `MRB_TT_STRING` and backed by an
`RString*`. Then `mrb_class_name` extracts the `RSTRING_PTR`:

https://github.com/mruby/mruby/blob/e04184185ab43b94980550e850d8813a415fa438/src/class.c#L2133-L2134

That `RString*`-backed `mrb_value` ultimately comes from `mrb_class_path`
which resolves the string from the symbol table:

https://github.com/mruby/mruby/blob/e04184185ab43b94980550e850d8813a415fa438/src/class.c#L2111

The allocation of the target `str` after resolving the class name
`mrb_value` and extracting its pointer is fragile and assumes the
`RString*` is "static". If the `RString*` is not static, the
interleaving of extracting the `RSTRING_PTR` followed by a subsequent
allocation might result in the class name `mrb_value` being garbage
collected, which will leave the extracted pointer invalid.

Fix this bad interleaving by allocating the destination string first
before taking a raw pointer to an `RString*`.
2022-07-24 09:33:51 -07:00
Yukihiro "Matz" Matsumoto e04184185a bigint.c: heavy restructuring of big-integers.
Instead of splitting mp_limb by bit operations (using HIGH/LOW macros),
now we use mp_limb2 (which is bigger integer size, e.g uint64_t). It
makes operations (especially mulitiplication) a lot faster. As a side
effect, it also reduces memory consumption (16,452,033 -> 15,545,853 on
my Linux machine).

Other changes:

- trailing zeros are removed after operations.
- division algorithm is simplified.
2022-07-23 07:50:30 +09:00
Yukihiro "Matz" Matsumoto c0a636c007 mruby-os-memsize/memsize.c: add up digit spaces for big-integers. 2022-07-21 20:56:32 +09:00
Yukihiro "Matz" Matsumoto 8bd1c56465 bigint.c (mpz_get_str): fixed wrong loop termination condition. 2022-07-21 20:40:35 +09:00
Yukihiro "Matz" Matsumoto 450382735b bigint.c (mrb_bint_to_s): shortcut for bigint zero. 2022-07-20 14:40:45 +09:00
Yukihiro "Matz" Matsumoto a4ce63abc5 bigint.c (mpz_sizeinbase): check zero length bigint. 2022-07-20 14:40:12 +09:00
Yukihiro "Matz" Matsumoto cfea0c28a0 bigint.c (digits): check zero length bigint. 2022-07-20 14:39:05 +09:00