Skip to content

Commit

Permalink
Guard for empty FileItems in CommonsFileUploadSupport
Browse files Browse the repository at this point in the history
This commit ensures that a FileItem is not empty before its value is
read.

Closes gh-31564
  • Loading branch information
poutsma committed Nov 8, 2023
1 parent de0cb53 commit d3ec939
Showing 1 changed file with 15 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2018 the original author or authors.
* Copyright 2002-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -255,16 +255,21 @@ protected MultipartParsingResult parseFileItems(List<FileItem> fileItems, String
for (FileItem fileItem : fileItems) {
if (fileItem.isFormField()) {
String value;
String partEncoding = determineEncoding(fileItem.getContentType(), encoding);
try {
value = fileItem.getString(partEncoding);
}
catch (UnsupportedEncodingException ex) {
if (logger.isWarnEnabled()) {
logger.warn("Could not decode multipart item '" + fileItem.getFieldName() +
"' with encoding '" + partEncoding + "': using platform default");
if (fileItem.getSize() > 0) {
String partEncoding = determineEncoding(fileItem.getContentType(), encoding);
try {
value = fileItem.getString(partEncoding);
}
catch (UnsupportedEncodingException ex) {
if (logger.isWarnEnabled()) {
logger.warn("Could not decode multipart item '" + fileItem.getFieldName() +
"' with encoding '" + partEncoding + "': using platform default");
}
value = fileItem.getString();
}
value = fileItem.getString();
}
else {
value = "";
}
String[] curParam = multipartParameters.get(fileItem.getFieldName());
if (curParam == null) {
Expand Down

0 comments on commit d3ec939

Please sign in to comment.