Skip to content

Commit eb64cfc

Browse files
changed request size limit for multi delete objects
Issue : CLDSRV-699
1 parent 615f831 commit eb64cfc

File tree

3 files changed

+20
-5
lines changed

3 files changed

+20
-5
lines changed

constants.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,10 @@ const constants = {
8989
// Maximum HTTP headers size allowed
9090
maxHttpHeadersSize: 14122,
9191

92+
// AWS sets the maximum number of objects deleted to 1000 for multiDeleteObjects
93+
// https://docs.aws.amazon.com/AmazonS3/latest/API/API_DeleteObjects.html
94+
maximumBatchDeleteObjects: 1000,
95+
9296
// hex digest of sha256 hash of empty string:
9397
emptyStringHash: crypto.createHash('sha256')
9498
.update('', 'binary').digest('hex'),

lib/api/api.js

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -219,8 +219,14 @@ const api = {
219219
}
220220
// issue 100 Continue to the client
221221
writeContinue(request, response);
222-
const MAX_POST_LENGTH = request.method === 'POST' ?
223-
1024 * 1024 : 1024 * 1024 / 2; // 1 MB or 512 KB
222+
const postLengthLimits = {
223+
// Multi-Object Delete can be large : up to 1000 keys of 1024 bytes is
224+
// already 1mb, with the other fields it could reach 2mb
225+
'multiObjectDelete': 2 * 1024 * 1024,
226+
};
227+
const defaultMaxPostLength = request.method === 'POST' ?
228+
1024 * 1024 : 512 * 1024; // 1 MB or 512 KB
229+
const MAX_POST_LENGTH = postLengthLimits[apiMethod] || defaultMaxPostLength;
224230
const post = [];
225231
let postLength = 0;
226232
request.on('data', chunk => {
@@ -242,7 +248,8 @@ const api = {
242248
if (postLength > MAX_POST_LENGTH) {
243249
log.error('body length is too long for request type',
244250
{ postLength });
245-
return next(errors.InvalidRequest);
251+
return next(errors.InvalidRequest.customizeDescription(
252+
`Maximum body length is ${MAX_POST_LENGTH} bytes, but received ${postLength}.`));
246253
}
247254
// Convert array of post buffers into one string
248255
request.post = Buffer.concat(post, postLength).toString();

lib/api/multiObjectDelete.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ const createAndStoreObject = require('./apiUtils/object/createAndStoreObject');
1919
const monitoring = require('../utilities/monitoringHandler');
2020
const metadataUtils = require('../metadata/metadataUtils');
2121
const { config } = require('../Config');
22+
const constants = require('../../constants');
2223
const { isRequesterNonAccountUser } = require('./apiUtils/authorization/permissionChecks');
2324
const { hasGovernanceBypassHeader, checkUserGovernanceBypass, ObjectLockInfo }
2425
= require('./apiUtils/object/objectLockHelpers');
@@ -492,8 +493,11 @@ function multiObjectDelete(authInfo, request, log, callback) {
492493
function parseXML(next) {
493494
return _parseXml(request.post,
494495
(err, quietSetting, objects) => {
495-
if (err || objects.length < 1 || objects.length > 1000) {
496-
return next(errors.MalformedXML);
496+
if (err || objects.length < 1 || objects.length > constants.maximumBatchDeleteObjects) {
497+
return next(errors.MalformedXML.customizeDescription(
498+
`The provided request tries to delete ${objects.length} objects, ` +
499+
`but AWS standard only allows ${constants.maximumBatchDeleteObjects} deletions per call. `
500+
));
497501
}
498502
return next(null, quietSetting, objects);
499503
});

0 commit comments

Comments
 (0)