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
Original file line number Diff line number Diff line change
Expand Up @@ -1939,9 +1939,13 @@ protected void doPost(HttpServletRequest request, HttpServletResponse response)
boolean siteQuotaUnlimited = siteQuota == 0;

// If the file size exceeds the max uploaded file size, post error message
// Note: fileSize comes from content-length header which includes multipart overhead
// HTTP multipart overhead: headers (~250B) + boundaries (~300B) + form fields (~350B) ≈ 1KB
// Use 64KB margin for safety with various browsers and large file scenarios
Long uploadMaxBytes = uploadMax * 1024L * 1024L;
Long margin = 64L * 1024L; // 64KB margin for multipart overhead
Long fileSizeKB = fileSize / 1024L;
Long fileSizeMB = fileSize / 1024L / 1024L;
if( fileSizeMB > uploadMax )
if( fileSize > (uploadMaxBytes + margin) )
{
addAlert(getState(request), rb.getFormattedMessage("alert.over-per-upload-quota", new Object[]{uploadMax}));
}
Expand Down
20 changes: 8 additions & 12 deletions kernel/api/src/main/java/org/sakaiproject/util/RequestFilter.java
Original file line number Diff line number Diff line change
Expand Up @@ -968,18 +968,14 @@ protected HttpServletRequest handleFileUpload(HttpServletRequest req, HttpServle
// to let commons-fileupload throw the exception on over-max, and also halt full processing of input fields
if (!m_uploadContinue)
{
// TODO: when we switch to commons-fileupload 1.2
// // either per file or overall request, as configured
// if (m_uploadMaxPerFile)
// {
// upload.setFileSizeMax(uploadMax);
// }
// else
// {
// upload.setSizeMax(uploadMax);
// }
// Apache Commons FileUpload uses >= internally, but we want to allow files exactly at the limit
// Add margin to account for HTTP multipart protocol overhead:
// - HTTP headers (~250 bytes), multipart boundaries (~300 bytes), form fields (~350 bytes)
// - Total typical overhead: ~1KB, but use 64KB margin for safety with large files
long margin = 64L * 1024L; // 64KB margin for multipart overhead

upload.setSizeMax(uploadMax);
upload.setSizeMax(uploadMax + margin);
upload.setFileSizeMax(uploadMax + margin);
}

try
Expand Down Expand Up @@ -1029,7 +1025,7 @@ else if (obj instanceof String)

// check the max, unless we are letting commons-fileupload throw exception on max exceeded
// Note: the continue option assumes the max is per-file, not overall.
if (m_uploadContinue && (item.getSize() > uploadMax))
if (m_uploadContinue && (item.getSize() >= uploadMax))
{
uploadOk = false;

Expand Down
Loading