Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix inverse_rle with negative lengths #853

Merged
merged 4 commits into from Apr 26, 2023
Merged

Fix inverse_rle with negative lengths #853

merged 4 commits into from Apr 26, 2023

Conversation

ararslan
Copy link
Member

Fixes #851.

src/misc.jl Outdated Show resolved Hide resolved
src/misc.jl Show resolved Hide resolved
@@ -65,6 +65,7 @@ function inverse_rle(vals::AbstractVector{T}, lens::AbstractVector{<:Integer}) w
p = 0
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Damn, sum(lens) on the line above can be negative, which throws an ErrorException instead of the expected ArgumentError. Should we add a check like this?

n = sum(lens)
n >= 0 || throw(ArgumentError("lengths must be non-negative"))

Otherwise, let's go back to the previous version.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a check on the sum per your suggestion since we need to compute the sum anyway in order to initialize the output array.

@nalimilan nalimilan merged commit 7928f90 into master Apr 26, 2023
12 of 18 checks passed
@nalimilan nalimilan deleted the aa/inverse_rle branch April 26, 2023 07:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Buffer overflow using inverse_rle
4 participants