Managed limits for pathological dice notation (overflow, huge rolls)#526
Merged
ianfhunter merged 15 commits intomainfrom Mar 30, 2026
Merged
Managed limits for pathological dice notation (overflow, huge rolls)#526ianfhunter merged 15 commits intomainfrom
ianfhunter merged 15 commits intomainfrom
Conversation
- Lexer: parse NUMBER with strtol (ERANGE) and max token length; yyterminate on error - Core: refuse rolls above GNOLL_MAX_DICE_PER_ROLL when not using CLT - Remove unsafe fast_atoi that wrapped on overflow - Centralize GNOLL_MAX_* limits in shared_header.h Co-authored-by: Ian Hunter <ianfhunter@users.noreply.github.com>
- validate_roll_string mirrors lexer/dice limits for defense in depth - Lazy-load dice.so so validation can be imported without a build - Add tests for huge literals and extreme XdY counts Co-authored-by: Ian Hunter <ianfhunter@users.noreply.github.com>
Owner
Author
✅ Snyk checks have passed. No issues have been found so far.
💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse. |
- Avoid free(NULL) / use-after-free when perform_roll returns NULL (e.g. dice cap) - Free symbolic symbol pool before return on failed do_roll - Add boundary and native-path tests; patch validation module for bypass tests Co-authored-by: Ian Hunter <ianfhunter@users.noreply.github.com>
Co-authored-by: Ian Hunter <ianfhunter@users.noreply.github.com>
- pytest from repo root finds src/python/code without PYTHONPATH - make test refreshes c_build via python target and skips pip wheel install Co-authored-by: Ian Hunter <ianfhunter@users.noreply.github.com>
- Add gnoll_validate_roll_request in roll_validation.c (digit test via '0'/'9') - Call from roll_full_options before lex/parse; export in shared_header.h - Remove Python validation.py; validate_roll_string wraps C via ctypes - Fix roll_full_options ctypes signature (c_longlong seed, int flags) - Makefile: yacc/lex outputs depend on grammar sources; y.tab.o/lex.yy.o depend on generated .c Co-authored-by: Ian Hunter <ianfhunter@users.noreply.github.com>
- C: gnoll_validate_roll_request_R for R .C() pattern; declare in shared_header.h - Java: validateRollRequest JNI + UTF-8 release in roll; Test asserts validate - JS/WASM: export _gnoll_validate_roll_request; validateRollRequest() helper - Go, Haskell, Rust, Ruby, Lua, PHP, C#, C++: call validate before roll where shown - Julia: fix roll() to use argument s; add validate_roll_request; test validate - Ruby/Lua: use int return from roll_and_write and check errors Co-authored-by: Ian Hunter <ianfhunter@users.noreply.github.com>
…iases - Haskell: extra-lib-dirs ../../build + extra-libraries dice (not path as library name) - Rust: add build.rs for rustc-link-search/lib; drop invalid Cargo [build] table - Rust target.mk: set LIBRARY_PATH to build dir (was literal $LD_LIBRARY_PATH) - Webpack: alias node:fs and node:crypto to browserify shims for gnollwasm.js - Rust: merge unsafe blocks to silence unused_unsafe warning Co-authored-by: Ian Hunter <ianfhunter@users.noreply.github.com>
…lib copy - Haskell: ccall imports are pure CInt; use let not <- in IO do-block - Haskell: copy libdice.so to src/haskell/lib for extra-lib-dirs inside tree - Webpack: NormalModuleReplacementPlugin for node:fs and node:crypto (alias failed) - Drop sudo cp to /usr/lib from haskell target Co-authored-by: Ian Hunter <ianfhunter@users.noreply.github.com>
- cabal build with -optl-Wl,-rpath,<abs>/src/haskell/lib so runtime finds libdice - Set LD_LIBRARY_PATH for linker subprocess if needed - main: pattern match on getArgs instead of head Co-authored-by: Ian Hunter <ianfhunter@users.noreply.github.com>
- Generate cabal.project.local with ghc-options rpath so cabal run relinks correctly - CI: export LD_LIBRARY_PATH to src/haskell/lib before cabal run (belt and suspenders) Co-authored-by: Ian Hunter <ianfhunter@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Pathological strings such as very long decimal literals or enormous
XdYcounts could stress GNOLL. Bounds checking is implemented ingnoll_validate_roll_request(roll_validation.c) androll_full_optionscalls it before lex/parse.roll_and_writeand friends still route throughroll_full_options, so existing FFI entry points remain protected.Language bindings were updated so callers can pre-check without rolling (and examples document the pattern):
gnoll_validate_roll_request(const char *);gnoll_validate_roll_request_Rfor R’s.C()pattern (sets*return_code).DiceNotationParser.validateRollRequest; JNI releases UTF-8 strings afterroll;Test.javaasserts validate._gnoll_validate_roll_request;validateRollRequest()ingnoll.js.roll_and_writereturn codes where applicable.validate_roll_request;roll(s)now usess(previous bug: hardcoded"1d20"); tests cover validate.gnoll_validate_roll_request_R+main.ruses sharednotationfor validate and roll.Python:
validate_roll_stringwraps C via ctypes;roll_full_optionsctypes use correct types (c_longlongseed, int flags).Build: Makefile ties generated yacc/lex outputs to grammar sources so
dice.socannot go stale.How Has This Been Tested
make test— 152 passed, 9 skippedChange Type
Checklist