Skip to content

Conversation

@tbelaire
Copy link

Right now it will consume an unbounded amount of memory if the remote server sends a response with nonsense all on one line.

It could also use a fixed limit instead of making it configurable if that is preferable.

Right now it will consume an unbounded amount of memory if the remote server sends a response with nonsense all on one line.
@jmehrens jmehrens linked an issue Jan 10, 2025 that may be closed by this pull request
public class ResponseInputStream {

private static final Integer INPUT_STREAM_BUFFER_MAX_SIZE =
Integer.parseInt(System.getProperty("org.eclipse.angus.mail.iap.inputStreamBufferMaxSize", "0"));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use primitive.
Use Math.max(x, 0) to clamp value.
Trap numberformatexception and use default. PropUtils has some helper methods.

Copy link
Member

@jbescos jbescos Jul 24, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be preferable to obtain that value from Session#properties instead of a System property, because System will apply to all instances of ResponseInputStream in the whole JVM.

There is only one reference to new ResponseInputStream that is happening in angus-mail/providers/imap/src/main/java/org/eclipse/angus/mail/iap/Protocol.java. It should be easy to add a new constructor in ResponseInputStream passing the Properties as an argument. In this way we can obtain that new parameter, and it opens the possibility to add more in the future.

// need count-avail more bytes
ba.grow(Math.max(minIncrement, count + incrementSlop - avail));
int amountToGrow = Math.max(minIncrement, count + incrementSlop - avail);
if (INPUT_STREAM_BUFFER_MAX_SIZE > 0 && buffer.length + amountToGrow > INPUT_STREAM_BUFFER_MAX_SIZE) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do an unsigned compare.

Suggested change
if (INPUT_STREAM_BUFFER_MAX_SIZE > 0 && buffer.length + amountToGrow > INPUT_STREAM_BUFFER_MAX_SIZE) {
if((buffer.length + amountToGrow) - INPUT_STREAM_BUFFER_MAX_SIZE > 0) {

Or use Integer.compareUnsigned.

@baoxinggit
Copy link

@tbelaire May I ask when this MR can be merged?

Copy link
Contributor

@jmehrens jmehrens left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Waiting on changes.

@jmehrens
Copy link
Contributor

@baoxinggit PR has to be updated per feedback.

Copy link
Contributor

@jmehrens jmehrens left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No new changes received.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

OutOfMemoryError has been occurred

4 participants