Fixed "Out-of-bounds Read" and "Divide-by-Zero" in ary_product_group()#6750
Fixed "Out-of-bounds Read" and "Divide-by-Zero" in ary_product_group()#6750matz merged 1 commit intomruby:masterfrom
ary_product_group()#6750Conversation
Summary of ChangesHello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request introduces crucial error handling to the Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request correctly addresses a divide-by-zero and an out-of-bounds read vulnerability in ary_product_group() by adding necessary checks. My review includes suggestions to improve the error reporting by using more specific exception types and clearer messages, which will enhance debuggability and align with mruby's conventions for similar errors.
| if (b <= 0) { | ||
| mrb_raise(mrb, E_RUNTIME_ERROR, "the array object has become invalid"); | ||
| } |
There was a problem hiding this comment.
The error message "the array object has become invalid" is quite generic. Since this error is triggered when one of the arrays for the product is empty, a more specific error would be more helpful for debugging. Consider using E_ARGUMENT_ERROR and a more descriptive message.
if (b <= 0) {
mrb_raise(mrb, E_ARGUMENT_ERROR, "cannot compute product with an empty array");
}| if (n >= RARRAY_LEN(self_ary)) { | ||
| mrb_raise(mrb, E_RUNTIME_ERROR, "the array object has become invalid"); | ||
| } |
There was a problem hiding this comment.
The error message "the array object has become invalid" is generic. This check is for an out-of-bounds index access. It would be more idiomatic and helpful to use E_INDEX_ERROR with a message like "index out of range", which is consistent with other array operations in mruby.
if (n >= RARRAY_LEN(self_ary)) {
mrb_raise(mrb, E_INDEX_ERROR, "index out of range");
}Reproduction:
- Out-of-bounds Read
```console
% build/host/bin/mruby -e '([nil] * 256).__product_group([[nil] * 256], 1 << 32, 256)'
zsh: segmentation fault (core dumped) build/host/bin/mruby -e
```
- Divide-by-Zero
```console
% build/host/bin/mruby -e '([nil] * 256).__product_group([[]], 1 << 32, 256)'
zsh: floating point exception (core dumped) build/host/bin/mruby -e '([nil] * 256).__product_group([[]], 1 << 32, 256)'
```
Reproduction:
Out-of-bounds Read
Divide-by-Zero