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

ArrayIndexOutOfBoundsException in ByteStack #3907

Open
djspiewak opened this issue Nov 26, 2023 · 3 comments · May be fixed by #3949
Open

ArrayIndexOutOfBoundsException in ByteStack #3907

djspiewak opened this issue Nov 26, 2023 · 3 comments · May be fixed by #3949
Labels

Comments

@djspiewak
Copy link
Member

Look I don't even know…

java.lang.ArrayIndexOutOfBoundsException: Index -268435455 out of bounds for length 402653184
  | => tat cats.effect.ByteStack$.push(ByteStack.scala:59)
	at cats.effect.IOFiber.runLoop(IOFiber.scala:560)
	at cats.effect.IOFiber.autoCedeR(IOFiber.scala:1439)
	at cats.effect.IOFiber.run(IOFiber.scala:119)
	at cats.effect.unsafe.WorkerThread.run(WorkerThread.scala:743)

See DispatcherSpec on the aioobe-reproduction tag at https://github.com/djspiewak/cats-effect

@durban
Copy link
Contributor

durban commented Nov 27, 2023

I can't reproduce this (I get OutOfMemoryErrors), but that exception more or less seems like what should happen if the size (stack(0)) overflowed from Int.MaxValue to Int.MinValue.

If in push the val c is Int.MinValue, then val s = (c >> 3) + 1 will be -268435455 (the same as in the exception), which is used as an index in line 59.

@armanbilge
Copy link
Member

Unless we want to add our own bounds check that gives a more helpful error message, can we close this?

@durban
Copy link
Contributor

durban commented Jan 9, 2024

We could detect the overflow earlier, by using Math.addExact.

@durban durban linked a pull request Jan 13, 2024 that will close this issue
@durban durban linked a pull request Jan 13, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants