carterkozak commented on a change in pull request #262:
URL:
https://github.com/apache/httpcomponents-client/pull/262#discussion_r514443722
##########
File path:
httpclient5/src/main/java/org/apache/hc/client5/http/entity/mime/HttpRFC7578Multipart.java
##########
@@ -137,13 +137,12 @@ protected void formatMultipartHeader(final MultipartPart
part, final OutputStrea
for (int i = 0; i < bytes.length; i++) {
final int b = bytes[i];
if (b == ESCAPE_CHAR) {
- try {
- final int u = digit16(bytes[++i]);
- final int l = digit16(bytes[++i]);
- buffer.append((char) ((u << 4) + l));
- } catch (final ArrayIndexOutOfBoundsException e) {
- throw new DecoderException("Invalid URL encoding: ",
e);
+ if (i >= bytes.length - 2) {
+ throw new DecoderException("Invalid URL encoding: too
short");
}
+ final int u = digit16(bytes[++i]);
+ final int l = digit16(bytes[++i]);
+ buffer.append((char) ((u << 4) + l));
Review comment:
+1 for validating preconditions instead of handling exceptions.
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]