kopia lustrzana https://github.com/gaul/s3proxy
UploadPartCopy: Fail if improper source range.
S3Proxy should check the format of the x-amz-copy-source-range value when handling an UploadPartCopy request. The patch changes the behavior to return an InvalidArgument error along with the matching error description to AWS S3. To match the error format, the S3Exception class is modified to return the actual error message, rather than the String version of the error code. Corresponding tests will be added to ceph/s3-tests. Fixes: #304pull/311/head
rodzic
1966efc269
commit
e37300dd3f
|
@ -63,7 +63,7 @@ public final class S3Exception extends Exception {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getMessage() {
|
public String getMessage() {
|
||||||
StringBuilder builder = new StringBuilder().append(error);
|
StringBuilder builder = new StringBuilder().append(super.getMessage());
|
||||||
if (!elements.isEmpty()) {
|
if (!elements.isEmpty()) {
|
||||||
builder.append(" ").append(elements);
|
builder.append(" ").append(elements);
|
||||||
}
|
}
|
||||||
|
|
|
@ -2469,20 +2469,33 @@ public class S3ProxyHandler {
|
||||||
GetOptions options = new GetOptions();
|
GetOptions options = new GetOptions();
|
||||||
String range = request.getHeader(AwsHttpHeaders.COPY_SOURCE_RANGE);
|
String range = request.getHeader(AwsHttpHeaders.COPY_SOURCE_RANGE);
|
||||||
long expectedSize = -1;
|
long expectedSize = -1;
|
||||||
if (range != null && range.startsWith("bytes=") &&
|
if (range != null) {
|
||||||
// ignore multiple ranges
|
if (!range.startsWith("bytes=") || range.indexOf(',') != -1 ||
|
||||||
range.indexOf(',') == -1) {
|
range.indexOf('-') == -1) {
|
||||||
range = range.substring("bytes=".length());
|
throw new S3Exception(S3ErrorCode.INVALID_ARGUMENT,
|
||||||
String[] ranges = range.split("-", 2);
|
"The x-amz-copy-source-range value must be of the form " +
|
||||||
if (ranges[0].isEmpty()) {
|
"bytes=first-last where first and last are the " +
|
||||||
options.tail(Long.parseLong(ranges[1]));
|
"zero-based offsets of the first and last bytes to copy");
|
||||||
} else if (ranges[1].isEmpty()) {
|
}
|
||||||
options.startAt(Long.parseLong(ranges[0]));
|
try {
|
||||||
} else {
|
range = range.substring("bytes=".length());
|
||||||
long start = Long.parseLong(ranges[0]);
|
String[] ranges = range.split("-", 2);
|
||||||
long end = Long.parseLong(ranges[1]);
|
if (ranges[0].isEmpty()) {
|
||||||
expectedSize = end - start + 1;
|
options.tail(Long.parseLong(ranges[1]));
|
||||||
options.range(start, end);
|
} else if (ranges[1].isEmpty()) {
|
||||||
|
options.startAt(Long.parseLong(ranges[0]));
|
||||||
|
} else {
|
||||||
|
long start = Long.parseLong(ranges[0]);
|
||||||
|
long end = Long.parseLong(ranges[1]);
|
||||||
|
expectedSize = end - start + 1;
|
||||||
|
options.range(start, end);
|
||||||
|
}
|
||||||
|
} catch (NumberFormatException nfe) {
|
||||||
|
throw new S3Exception(S3ErrorCode.INVALID_ARGUMENT,
|
||||||
|
"The x-amz-copy-source-range value must be of the form " +
|
||||||
|
"bytes=first-last where first and last are the " +
|
||||||
|
"zero-based offsets of the first and last bytes to copy",
|
||||||
|
nfe);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Ładowanie…
Reference in New Issue