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

Avoid infinite loop in readbytes!(s, UInt8[], 1) #194

Merged
merged 2 commits into from
Mar 28, 2024
Merged

Conversation

nhz2
Copy link
Member

@nhz2 nhz2 commented Mar 27, 2024

Fixes #193
This fixes the edge case of calling readbytes! with an empty b but non-zero nb by resizing b initially to 32 bytes if b is too small.

@nhz2 nhz2 marked this pull request as ready for review March 27, 2024 15:45
@nhz2 nhz2 requested a review from mkitti March 27, 2024 15:52
mkitti
mkitti previously approved these changes Mar 27, 2024
@mkitti
Copy link
Member

mkitti commented Mar 27, 2024

Why 32? Should we make it a constant somewhere?

@nhz2
Copy link
Member Author

nhz2 commented Mar 27, 2024

Just a small number, readbytes! is usually called with a 1024 byte buffer in read so this issue usually isn't a problem: https://github.com/JuliaLang/julia/blob/v1.9.4/base/io.jl#L1000

I looked in resize! and if understand this correctly, https://github.com/JuliaLang/julia/blob/4ee10228176c960fc3d0046390ab2ef4df7ab08a/base/array.jl#L1040-L1041 seems to resize to a minimum of 8 bytes so I think I'll change 32 to 8 here as well.

@nhz2 nhz2 merged commit 9d69586 into master Mar 28, 2024
22 checks passed
@nhz2 nhz2 deleted the nz/fix-readbytes-loop branch March 28, 2024 00:05
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.

Infinite loop in readbytes!(s, UInt8[], 1)
2 participants