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 ByteBuffer#asReadOnlyBuffer() #29

Merged
merged 2 commits into from
Feb 7, 2022

Conversation

overheadhunter
Copy link
Member

Except for some cases where a ReadOnlyBuffer is used in a very limited scope, we don't want to use them in conjunction with Ciphers and Macs for the following reason:

A readonly buffer doesn't allow direct access to its byte[], regardless of whether its on-heap or not. However, Ciphers are more efficient when ByteBuffer#hasArray() returns true (as can be seen e.g. in CipherSpi) as they don't need to copy bytes from the buffers to some internal byte[].

To avoid allocations of byte[], we will therefore use .duplicate() instead of .asReadOnlyBuffer(), even if we don't need write access to said buffers.

…alse, leading to lots of byte[] allocations in Cipher-internal code
@sonarqubecloud
Copy link

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

100.0% 100.0% Coverage
11.8% 11.8% Duplication

@overheadhunter overheadhunter self-assigned this Jan 26, 2022
Copy link
Member

@SailReal SailReal left a comment

Choose a reason for hiding this comment

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

LGTM 👍 and tested it using our new min version (Android 8.0) with vault format 7/8

* create/open a vault
* create/open a file/folder

@overheadhunter overheadhunter merged commit 0830881 into develop Feb 7, 2022
@overheadhunter overheadhunter deleted the feature/avoid-readonly-bytebuffers branch February 7, 2022 15:29
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.

2 participants