Copilot commented on code in PR #4249:
URL: https://github.com/apache/solr/pull/4249#discussion_r3006689407
##########
solr/core/src/java/org/apache/solr/handler/configsets/UploadConfigSet.java:
##########
@@ -80,13 +81,22 @@ public SolrJerseyResponse uploadConfigSet(
try (ZipInputStream zis = new ZipInputStream(requestBody,
StandardCharsets.UTF_8)) {
boolean hasEntry = false;
ZipEntry zipEntry;
- while ((zipEntry = zis.getNextEntry()) != null) {
- hasEntry = true;
- String filePath = zipEntry.getName();
- filesToDelete.remove(filePath);
- if (!zipEntry.isDirectory()) {
- configSetService.uploadFileToConfig(configSetName, filePath,
zis.readAllBytes(), true);
+ try {
+ while ((zipEntry = zis.getNextEntry()) != null) {
+ hasEntry = true;
+ String filePath = zipEntry.getName();
+ filesToDelete.remove(filePath);
+ if (!zipEntry.isDirectory()) {
+ configSetService.uploadFileToConfig(configSetName, filePath,
zis.readAllBytes(), true);
+ }
}
+ } catch (ZipException e) {
+ throw new SolrException(
+ SolrException.ErrorCode.BAD_REQUEST,
+ "Failed to read the uploaded zip file. The file may be malformed
or use an unsupported format. "
+ + "Please recreate the zip file using standard compression
tools: "
+ + e.getMessage(),
+ e);
Review Comment:
The BAD_REQUEST message here advises recreating the zip using “standard
compression tools”, but the new test’s javadoc notes that common tooling (e.g.,
`zip -r` with an empty file) can legitimately produce this
STORED+data-descriptor variant. Consider rewording the message to explain the
specific unsupported ZIP feature (STORED entry with data descriptor / EXT flag)
and suggest actionable mitigations (e.g., use DEFLATED compression or avoid
0-byte STORED entries with descriptors), rather than implying the zip was
created with non-standard tools. Also, appending `e.getMessage()`
unconditionally can yield a trailing "null"; guard against null or format it
conditionally.
```suggestion
StringBuilder msg =
new StringBuilder(
"Failed to read the uploaded zip file. The file may be
malformed or use an unsupported ZIP feature (for example, a STORED entry with a
data descriptor / EXT flag). "
+ "Try recreating the zip using DEFLATED compression or
avoid zero-byte STORED entries with data descriptors.");
String underlying = e.getMessage();
if (underlying != null && !underlying.isEmpty()) {
msg.append(" Underlying error: ").append(underlying);
}
throw new SolrException(SolrException.ErrorCode.BAD_REQUEST,
msg.toString(), e);
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]