Skip to content

Commit

Permalink
Use long for file offsets
Browse files Browse the repository at this point in the history
Using an int limits the offset to about 2GB, which might not be sufficient for very large files.
Using a long results in an offset of 9EB, which should be sufficient.
  • Loading branch information
vierbergenlars committed Nov 28, 2024
1 parent 0193e0c commit ac57657
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -329,26 +329,26 @@ public Resource getResource(S entity, PropertyPath propertyPath, GetResourcePara
return r;
}

private int getOffset(Resource r, GetResourceParams params) {
private long getOffset(Resource r, GetResourceParams params) {
int offset = 0;

if (r instanceof RangeableResource == false)
return offset;
if (params.getRange() == null)
return offset;

return Integer.parseInt(StringUtils.substringBetween(params.getRange(), "bytes=", "-"));
return Long.parseUnsignedLong(StringUtils.substringBetween(params.getRange(), "bytes=", "-"));
}

private int getOffset(Resource r, org.springframework.content.commons.store.GetResourceParams params) {
int offset = 0;
private long getOffset(Resource r, org.springframework.content.commons.store.GetResourceParams params) {
long offset = 0;

if (r instanceof RangeableResource == false)
return offset;
if (params.getRange() == null)
return offset;

return Integer.parseInt(StringUtils.substringBetween(params.getRange(), "bytes=", "-"));
return Long.parseUnsignedLong(StringUtils.substringBetween(params.getRange(), "bytes=", "-"));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ private SecretKey generateDataKey() {
return KEY_GENERATOR.generateKey();
}

private InputStream decryptInputStream(final SecretKeySpec secretKeySpec, byte[] nonce, int offset, InputStream is) throws NoSuchPaddingException, NoSuchAlgorithmException, InvalidKeyException, BadPaddingException, IllegalBlockSizeException, IOException, InvalidAlgorithmParameterException {
private InputStream decryptInputStream(final SecretKeySpec secretKeySpec, byte[] nonce, long offset, InputStream is) throws NoSuchPaddingException, NoSuchAlgorithmException, InvalidKeyException, BadPaddingException, IllegalBlockSizeException, IOException, InvalidAlgorithmParameterException {
Cipher cipher = Cipher.getInstance(transformation);

byte[] iv = new byte[128 / 8];
Expand Down Expand Up @@ -124,7 +124,7 @@ private SecretKeySpec decryptKey(byte[] encryptedKey, String keyName) {
return key;
}

public InputStream decrypt(byte[] ecryptedContext, InputStream is, int offset, String keyName) {
public InputStream decrypt(byte[] ecryptedContext, InputStream is, long offset, String keyName) {

byte[] key = new byte[105];
System.arraycopy(ecryptedContext, 0, key, 0, 105);
Expand Down

0 comments on commit ac57657

Please sign in to comment.