cryptomator / cryptomator/cryptolib
OoM crash: No upper limit for Scrypt cost parameter
- Dominant language
- Java
- Stars
- 98
- Forks
- 35
- Avg merge
- 1d 6h
- Merged PRs (30d)
- 1
Description
The scrypt implementation does not enforce an upper bound on its input:
https://github.com/cryptomator/cryptolib/blob/8fabeee72910cd65f73daa9cfc8dc44ffd82605a/src/main/java/org/cryptomator/cryptolib/common/Scrypt.java#L64-L81
After validating the input, scrypt creates three arrays B, XY and V with sizes 128 * P * blocksize, 256 * blockSize and 128 * blockSize * costParam. With big enough parameters, the worst case is a JVM crashes with an OoM error.
This can be problematic, since in a masterkey file `blockSize` and `costParam` are defined (P is fixed) and a masterkey file is only verfied once the masterkey is loaded. Using `[MasterkeyFileAccess::load](https://github.com/cryptomator/cryptolib/blob/8fabeee72910cd65f73daa9cfc8dc44ffd82605a/src/main/java/org/cryptomator/cryptolib/common/MasterkeyFileAccess.java#L117) arbitrary values are handed over to scrypt, only checking for lower limits.
### Remarks
Reported by https://github.com/daothinh.
Contributor guide
No contributing guide indexed for this repository
Research direction
Start with the parameter validation and array allocations in src/main/java/org/cryptomator/cryptolib/common/Scrypt.java, then trace how values reach them from MasterkeyFileAccess.load in src/main/java/org/cryptomator/cryptolib/common/MasterkeyFileAccess.java. Check existing tests for these entry points and establish that oversized parameters are rejected before excessive allocation, with regression coverage for the failure.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- cryptography, security
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Active
- Clarity
- Mostly clear
- Newbie friendliness
- 64/100