Skip to content

Commit

Permalink
[#443] Avoid integer overflow
Browse files Browse the repository at this point in the history
  • Loading branch information
Inigo Lopez de Heredia committed May 31, 2016
1 parent 324710c commit d613eac
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions app/src/main/java/org/akvo/flow/api/S3Api.java
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,10 @@ public void get(String objectKey, File dst) throws IOException {
}

public boolean put(String objectKey, File file, String type, boolean isPublic) throws IOException {
// Calculate data size, up to 2 GB
final int size = file.length() < Integer.MAX_VALUE ? (int)file.length() : -1;

// Get date and signature
final int size = (int)file.length();// long version was added on API level 19
final byte[] rawMd5 = FileUtil.getMD5Checksum(file);
final String md5Base64 = Base64.encodeToString(rawMd5, Base64.NO_WRAP);
final String md5Hex = FileUtil.hexMd5(rawMd5);
Expand All @@ -143,7 +145,11 @@ public boolean put(String objectKey, File file, String type, boolean isPublic) t
try {
conn = (HttpURLConnection) url.openConnection();
conn.setDoOutput(true);
conn.setFixedLengthStreamingMode(size);
if (size > 0) {
conn.setFixedLengthStreamingMode(size);
} else {
conn.setChunkedStreamingMode(0);
}
conn.setRequestMethod("PUT");
conn.setRequestProperty("Content-MD5", md5Base64);
conn.setRequestProperty("Content-Type", type);
Expand Down

0 comments on commit d613eac

Please sign in to comment.