Avoid panic from deserialized Uniform<char> where range == 0 - #1831
Open
dhardy wants to merge 5 commits into
Open
Avoid panic from deserialized Uniform<char> where range == 0#1831dhardy wants to merge 5 commits into
Uniform<char> where range == 0#1831dhardy wants to merge 5 commits into
Conversation
There was a problem hiding this comment.
Pull request overview
This PR aims to prevent panics when sampling a Uniform<char> that has been deserialized from (potentially attacker-controlled) serde data, by tightening the internal maximum-value logic used by the UniformChar deserialization guard.
Changes:
- Update
UniformInt::maxto treatrange == 0(full-range marker) as having a maximum of$ty::MAX. - Refactor and extend the
Uniform<char>bad-deserialization test to cover therange == 0, low = 5payload. - Add a changelog entry documenting the fix.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
src/distr/uniform_other.rs |
Refactors Uniform<char> serde failure test helper and adds coverage for an additional failing payload. |
src/distr/uniform_int.rs |
Adjusts UniformInt::max behavior when range == 0. |
CHANGELOG.md |
Documents the intended panic-avoidance fix. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
dhardy
force-pushed
the
push-qvsoqsoosqmp
branch
from
August 30, 2026 09:36
32adc51 to
8224741
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
Suppressed comments (1)
Previously missed (1) — in code that hasn't changed since the last review.
src/distr/uniform_other.rs:324
- In builds with
--no-default-features --features serde(i.e. without theallocfeature), thecolparameter is unused because it’s only referenced inside#[cfg(feature = "alloc")], which can trigger anunused_variableswarning in this test.
fn do_test(json: &str, col: usize) {
let result = serde_json::from_str::<Uniform<char>>(json);
assert!(result.is_err());
let err = result.unwrap_err();
assert_eq!(err.classify(), serde_json::error::Category::Data);
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.
CHANGELOG.mdentrySummary
Fixes #1827. Closes #1829.
Details
Fixes the internal method
UniformInt::maxwhich previously ignored the special casesrange == 0and wherelow + rangeoverflows.