Skip to content

Commit

Permalink
Set outputLength correctly on open ended range requests to encryptedB…
Browse files Browse the repository at this point in the history
…lobStore

Open ended ranged requests to encrypted files resulted in incorrect Content-Length headers in the response because of a bug in the Decryption class.  In EncryptedBlobStore the length is set to -1 by default. On open-ended ranged GET requests this value is passed to the Decryption constructor, which in turn only sets outputLength if an offset is given without a length, but -1 is used to represent no length given. After this change the outputLength is set correctly in this constructor.  Fixes #698.
  • Loading branch information
ptemarvelde authored Oct 16, 2024
1 parent 33b3427 commit 6185f2b
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src/main/java/org/gaul/s3proxy/crypto/Decryption.java
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,8 @@ public Decryption(SecretKeySpec key, BlobStore blobStore,
// calculate the offset
calculateOffset(offset);

// if there is a offset and a length set the output length
if (offset > 0 && length == 0) {
// if there is a offset and no length set the output length
if (offset > 0 && length <= 0) {
outputLength = unencryptedSize - offset;
}
}
Expand Down
26 changes: 22 additions & 4 deletions src/test/java/org/gaul/s3proxy/EncryptedBlobStoreLiveTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -159,11 +159,29 @@ public void testPartialContent() throws InterruptedException, IOException {
options.range(0, 19);
object = this.getApi().getObject(containerName, blobName, options);

InputStreamReader r =
new InputStreamReader(object.getPayload().openStream());
InputStreamReader r = new InputStreamReader(
object.getPayload().openStream());
BufferedReader reader = new BufferedReader(r);
String partialContent = reader.lines().collect(Collectors.joining());
assertThat(partialContent).isEqualTo(content.substring(0, 20));
String partialContent = reader.lines()
.collect(Collectors.joining());

assertThat(partialContent).isEqualTo(
content.substring(0, 20));
assertThat((long) partialContent.length()).isEqualTo(
object.getMetadata().getContentMetadata().getContentLength());

// open ended range request
options = new GetOptions();
options.startAt(10);
object = this.getApi().getObject(containerName, blobName, options);

r = new InputStreamReader(object.getPayload().openStream());
reader = new BufferedReader(r);
partialContent = reader.lines().collect(Collectors.joining());

assertThat(partialContent).isEqualTo(content.substring(10));
assertThat((long) partialContent.length()).isEqualTo(
object.getMetadata().getContentMetadata().getContentLength());
}

@Test
Expand Down

0 comments on commit 6185f2b

Please sign in to comment.