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

InputStreamDecrypter read() is not InputStream compliant #10

Closed
spheroid opened this issue Sep 4, 2023 · 1 comment
Closed

InputStreamDecrypter read() is not InputStream compliant #10

spheroid opened this issue Sep 4, 2023 · 1 comment

Comments

@spheroid
Copy link
Contributor

spheroid commented Sep 4, 2023

The InputStream.read() spec states:

The value byte is returned as an int in the range 0 to 255. If no byte is available because the end of the stream has been reached, the value -1 is returned.

The current InputStreamDecrypter.read() currently behaves incorrectly as it returns signed ints which both:

  1. Breaks every implementation that relies on this behavior.
  2. Masks the -1 return value as it cannot be distinguished from 0xff.
spheroid added a commit to spheroid/tink-java that referenced this issue Sep 5, 2023
Convert the read signed integer to unsigned before returning it, because it is the behavior defined in the InputStream interface. It also makes it possible to distinguish between errors and successful read operations.

Fixes tink-crypto#10.
@juergw
Copy link
Contributor

juergw commented Sep 19, 2023

Thanks for finding this! Yes, this is an obvious bug.

copybara-service bot pushed a commit that referenced this issue Sep 20, 2023
These test also show the issue reported in
#10

InputStream.read should return a value in [0,255]:
https://docs.oracle.com/javase/8/docs/api/java/io/InputStream.html#read--

PiperOrigin-RevId: 566966884
Change-Id: Iba00859942fc63483074d00a69acd3839cb98e0a
copybara-service bot pushed a commit that referenced this issue Sep 21, 2023
PiperOrigin-RevId: 567268571
Change-Id: Ie695bfd7094384535e394c6487200c65bdc558c6
tholenst pushed a commit to tink-crypto/tink that referenced this issue Dec 4, 2023
These test also show the issue reported in
tink-crypto/tink-java#10

InputStream.read should return a value in [0,255]:
https://docs.oracle.com/javase/8/docs/api/java/io/InputStream.html#read--

PiperOrigin-RevId: 566966884
tholenst pushed a commit to tink-crypto/tink that referenced this issue Dec 4, 2023
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 a pull request may close this issue.

2 participants