Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions lib/api/objectCopy.js
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,16 @@ function objectCopy(authInfo, request, sourceBucket,
request.sourceServerAccessLog && (request.sourceServerAccessLog.error = err);
return next(err, destBucketMD);
}
const sourceSize = parseInt(sourceObjMD['content-length'], 10);
if (sourceSize > constants.maximumAllowedUploadSize) {
Comment thread
tcarmet marked this conversation as resolved.
Outdated
log.debug('copy source object too large', { sourceSize });
const err = errorInstances.InvalidRequest.customizeDescription(
'The specified copy source is larger than the maximum ' +
`allowable size for a copy source: ${constants.maximumAllowedUploadSize}`);
// eslint-disable-next-line no-param-reassign
request.sourceServerAccessLog && (request.sourceServerAccessLog.error = err);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a strange construct, I would rather do a plain if statement

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it is, but what I'm doing here is following the same pattern found across the file/project. I could go for a if and leave a bit of inconsistency or change it as whole. What I went with now is just consistency.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, generally speaking I tend to prefer having an inconsistent but incrementally correct style than a consistently subpar style, but that's my take, do as you think is best!

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm fine with that, I think I needed an extra opinion to make a call so thanks, will have a look into it.

return next(err, destBucketMD);
}
const headerValResult =
validateHeaders(request.headers,
sourceObjMD['last-modified'],
Expand Down
47 changes: 46 additions & 1 deletion tests/unit/api/objectCopy.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ const { cleanup, DummyRequestLogger, makeAuthInfo, versioningTestUtils }
const mpuUtils = require('../utils/mpuUtils');
const metadata = require('../metadataswitch');
const { data } = require('../../../lib/data/wrapper');
const { objectLocationConstraintHeader } = require('../../../constants');
const constants = require('../../../constants');
const { objectLocationConstraintHeader } = constants;
const { fakeMetadataArchive } = require('../../functional/aws-node-sdk/test/utils/init');
const { config } = require('../../../lib/Config');

Expand Down Expand Up @@ -640,3 +641,47 @@ describe('objectCopy with objectKeyByteLimit', () => {
});
});
});

describe('objectCopy source size limit', () => {
const testPutObjectRequest = versioningTestUtils.createPutObjectRequest(sourceBucketName, objectKey, objData[0]);
const sourceSize = objData[0].length;
let originalMaximumUploadSize;

before(done => {
cleanup();
originalMaximumUploadSize = constants.maximumAllowedUploadSize;
async.series([
callback => bucketPut(authInfo, putDestBucketRequest, log, callback),
callback => bucketPut(authInfo, putSourceBucketRequest, log, callback),
callback => objectPut(authInfo, testPutObjectRequest, undefined, log, callback),
], done);
});

after(() => {
constants.maximumAllowedUploadSize = originalMaximumUploadSize;
cleanup();
});
Comment thread
tcarmet marked this conversation as resolved.
Comment thread
tcarmet marked this conversation as resolved.

it('should allow CopyObject when source size equals the limit', done => {
constants.maximumAllowedUploadSize = sourceSize;
const testObjectCopyRequest = _createObjectCopyRequest(destBucketName);
objectCopy(authInfo, testObjectCopyRequest, sourceBucketName, objectKey,
undefined, log, err => {
assert.ifError(err);
done();
});
});

it('should reject CopyObject when source size exceeds the limit', done => {
constants.maximumAllowedUploadSize = sourceSize - 1;
const testObjectCopyRequest = _createObjectCopyRequest(destBucketName);
objectCopy(authInfo, testObjectCopyRequest, sourceBucketName, objectKey,
undefined, log, err => {
assert(err);
assert.strictEqual(err.is.InvalidRequest, true);
assert.match(err.description,
/The specified copy source is larger than the maximum allowable size for a copy source/);
done();
});
});
});
Loading