Closed infeo closed 6 years ago
Since we explicitly introduced the IllegalArgumentException to find bugs easier, we should document it.
Issue is related to #22.
Reopening since we've reconsidered:
The IllegalArgumentException thrown by Cryptors.cleartextSize
should be handled by CryptoFS within the size()
method itself.
In the case of a invalid ciphertext a size of 0
should be returned. The [contract of this method](https://docs.oracle.com/javase/10/docs/api/java/nio/file/attribute/BasicFileAttributes.html#size()) states:
Returns the size of the file (in bytes). The size may differ from the actual size on the file system due to compression, support for sparse files, or other reasons. The size of files that are not regular files is implementation specific and therefore unspecified.
Even is a ciphertext file is broken, it is still reported as a "regular" file (not a dir, not a symlink, ...). Therefore the returned value must be a valid number of bytes, i.e. a positive integer.
A file is then reported as an "empty" file in dir listings. When attempting to access a malformed file, we can still throw an IOException. This seems to be the most correct way to handle broken files.
The caused highlevel-error is described here: https://github.com/cryptomator/cryptomator/issues/673
Getting the size of an invalid cyphertext file throws an (undocumented) IllegalArgumentException.
We should either document this behavoiur und handle it in the corresponding nio-adapter libraries or should change it e.g. such that a negative size is returned (or something else).
The problem causing code is in CrypoBasicFileAttribute: https://github.com/cryptomator/cryptofs/blob/04cb671690ae87c5baf03a57a53d1d224a1d404f/src/main/java/org/cryptomator/cryptofs/CryptoBasicFileAttributes.java#L58