Skip to content

Fix NPE when upgrade message fails to aggregate#14816

Merged
chrisvest merged 7 commits intonetty:4.1from
yawkat:upgrade-npe
Feb 18, 2025
Merged

Fix NPE when upgrade message fails to aggregate#14816
chrisvest merged 7 commits intonetty:4.1from
yawkat:upgrade-npe

Conversation

@yawkat
Copy link
Copy Markdown
Contributor

@yawkat yawkat commented Feb 13, 2025

Motivation:

When an HTTP message fails to aggregate, for example due to an invalid 'Expect' header, MessageAggregator does not produce a FullHttpRequest. HttpServerUpgradeHandler would then continue with the next request, wrongly believing it to be an upgrade request, even though only the previous one was. This produces an NPE:

Caused by: java.lang.NullPointerException: Cannot invoke "java.lang.CharSequence.length()" because "header" is null
	at io.netty.handler.codec.http.HttpServerUpgradeHandler.splitHeader(HttpServerUpgradeHandler.java:429)
	at io.netty.handler.codec.http.HttpServerUpgradeHandler.upgrade(HttpServerUpgradeHandler.java:328)
	at io.netty.handler.codec.http.HttpServerUpgradeHandler.decode(HttpServerUpgradeHandler.java:290)
	at io.netty.handler.codec.http.HttpServerUpgradeHandler.decode(HttpServerUpgradeHandler.java:40)
	at io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:91)
	... 35 common frames omitted

Modification:

When the upgrade handler sees a LastHttpContent, cancel the current upgrade and cancel aggregation.

Result:

No NPE for this input.

Found by fuzzing.

Motivation:

When an HTTP message fails to aggregate, for example due to an invalid 'Expect' header, MessageAggregator does not produce a FullHttpRequest. HttpServerUpgradeHandler would then continue with the next request, wrongly believing it to be an upgrade request, even though only the previous one was. This produces an NPE:

```
Caused by: java.lang.NullPointerException: Cannot invoke "java.lang.CharSequence.length()" because "header" is null
	at io.netty.handler.codec.http.HttpServerUpgradeHandler.splitHeader(HttpServerUpgradeHandler.java:429)
	at io.netty.handler.codec.http.HttpServerUpgradeHandler.upgrade(HttpServerUpgradeHandler.java:328)
	at io.netty.handler.codec.http.HttpServerUpgradeHandler.decode(HttpServerUpgradeHandler.java:290)
	at io.netty.handler.codec.http.HttpServerUpgradeHandler.decode(HttpServerUpgradeHandler.java:40)
	at io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:91)
	... 35 common frames omitted
```

Modification:

When the upgrade handler sees a LastHttpContent, cancel the current upgrade and cancel aggregation.

Result:

No NPE for this input.

Found by fuzzing.
}

private void releaseCurrentMessage() {
protected final void releaseCurrentMessage() {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Maybe the compatibility checkers would like it more if this wasn't final.

@yawkat
Copy link
Copy Markdown
Contributor Author

yawkat commented Feb 13, 2025 via email

@chrisvest chrisvest merged commit 84120a7 into netty:4.1 Feb 18, 2025
15 checks passed
@chrisvest chrisvest added this to the 4.1.119.Final milestone Feb 18, 2025
chrisvest pushed a commit to chrisvest/netty that referenced this pull request Feb 18, 2025
Motivation:

When an HTTP message fails to aggregate, for example due to an invalid
'Expect' header, MessageAggregator does not produce a FullHttpRequest.
HttpServerUpgradeHandler would then continue with the next request,
wrongly believing it to be an upgrade request, even though only the
previous one was. This produces an NPE:

```
Caused by: java.lang.NullPointerException: Cannot invoke "java.lang.CharSequence.length()" because "header" is null
	at io.netty.handler.codec.http.HttpServerUpgradeHandler.splitHeader(HttpServerUpgradeHandler.java:429)
	at io.netty.handler.codec.http.HttpServerUpgradeHandler.upgrade(HttpServerUpgradeHandler.java:328)
	at io.netty.handler.codec.http.HttpServerUpgradeHandler.decode(HttpServerUpgradeHandler.java:290)
	at io.netty.handler.codec.http.HttpServerUpgradeHandler.decode(HttpServerUpgradeHandler.java:40)
	at io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:91)
	... 35 common frames omitted
```

Modification:

When the upgrade handler sees a LastHttpContent, cancel the current
upgrade and cancel aggregation.

Result:

No NPE for this input.

Found by fuzzing.
chrisvest pushed a commit to chrisvest/netty that referenced this pull request Feb 18, 2025
Motivation:

When an HTTP message fails to aggregate, for example due to an invalid
'Expect' header, MessageAggregator does not produce a FullHttpRequest.
HttpServerUpgradeHandler would then continue with the next request,
wrongly believing it to be an upgrade request, even though only the
previous one was. This produces an NPE:

```
Caused by: java.lang.NullPointerException: Cannot invoke "java.lang.CharSequence.length()" because "header" is null
    at io.netty.handler.codec.http.HttpServerUpgradeHandler.splitHeader(HttpServerUpgradeHandler.java:429)
    at io.netty.handler.codec.http.HttpServerUpgradeHandler.upgrade(HttpServerUpgradeHandler.java:328)
    at io.netty.handler.codec.http.HttpServerUpgradeHandler.decode(HttpServerUpgradeHandler.java:290)
    at io.netty.handler.codec.http.HttpServerUpgradeHandler.decode(HttpServerUpgradeHandler.java:40)
    at io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:91)
    ... 35 common frames omitted
```

Modification:

When the upgrade handler sees a LastHttpContent, cancel the current
upgrade and cancel aggregation.

Result:

No NPE for this input.

Found by fuzzing.
normanmaurer pushed a commit that referenced this pull request Feb 18, 2025
Motivation:

When an HTTP message fails to aggregate, for example due to an invalid
'Expect' header, MessageAggregator does not produce a FullHttpRequest.
HttpServerUpgradeHandler would then continue with the next request,
wrongly believing it to be an upgrade request, even though only the
previous one was. This produces an NPE:

```
Caused by: java.lang.NullPointerException: Cannot invoke "java.lang.CharSequence.length()" because "header" is null
	at io.netty.handler.codec.http.HttpServerUpgradeHandler.splitHeader(HttpServerUpgradeHandler.java:429)
	at io.netty.handler.codec.http.HttpServerUpgradeHandler.upgrade(HttpServerUpgradeHandler.java:328)
	at io.netty.handler.codec.http.HttpServerUpgradeHandler.decode(HttpServerUpgradeHandler.java:290)
	at io.netty.handler.codec.http.HttpServerUpgradeHandler.decode(HttpServerUpgradeHandler.java:40)
	at io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:91)
	... 35 common frames omitted
```

Modification:

When the upgrade handler sees a LastHttpContent, cancel the current
upgrade and cancel aggregation.

Result:

No NPE for this input.

Found by fuzzing.

Co-authored-by: Jonas Konrad <jonas.konrad@oracle.com>
normanmaurer pushed a commit that referenced this pull request Feb 18, 2025
Motivation:

When an HTTP message fails to aggregate, for example due to an invalid
'Expect' header, MessageAggregator does not produce a FullHttpRequest.
HttpServerUpgradeHandler would then continue with the next request,
wrongly believing it to be an upgrade request, even though only the
previous one was. This produces an NPE:

```
Caused by: java.lang.NullPointerException: Cannot invoke "java.lang.CharSequence.length()" because "header" is null
    at io.netty.handler.codec.http.HttpServerUpgradeHandler.splitHeader(HttpServerUpgradeHandler.java:429)
    at io.netty.handler.codec.http.HttpServerUpgradeHandler.upgrade(HttpServerUpgradeHandler.java:328)
    at io.netty.handler.codec.http.HttpServerUpgradeHandler.decode(HttpServerUpgradeHandler.java:290)
    at io.netty.handler.codec.http.HttpServerUpgradeHandler.decode(HttpServerUpgradeHandler.java:40)
    at io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:91)
    ... 35 common frames omitted
```

Modification:

When the upgrade handler sees a LastHttpContent, cancel the current
upgrade and cancel aggregation.

Result:

No NPE for this input.

Found by fuzzing.

---------

Co-authored-by: Jonas Konrad <jonas.konrad@oracle.com>
dongjoon-hyun added a commit to apache/spark that referenced this pull request Mar 4, 2025
### What changes were proposed in this pull request?

This PR aims to Upgrade Netty to 4.1.119.Final.

### Why are the changes needed?

- https://github.com/netty/netty/milestone/309?closed=1
  - netty/netty#14855
  - netty/netty#14830
  - netty/netty#14816
  - netty/netty#14810

### Does this PR introduce _any_ user-facing change?

No behavior change.

### How was this patch tested?

Pass the CIs.

### Was this patch authored or co-authored using generative AI tooling?

No.

Closes #50150 from dongjoon-hyun/SPARK-51387.

Authored-by: Dongjoon Hyun <dongjoon@apache.org>
Signed-off-by: Dongjoon Hyun <dongjoon@apache.org>
dongjoon-hyun added a commit to apache/spark that referenced this pull request Mar 4, 2025
### What changes were proposed in this pull request?

This PR aims to Upgrade Netty to 4.1.119.Final.

### Why are the changes needed?

- https://github.com/netty/netty/milestone/309?closed=1
  - netty/netty#14855
  - netty/netty#14830
  - netty/netty#14816
  - netty/netty#14810

### Does this PR introduce _any_ user-facing change?

No behavior change.

### How was this patch tested?

Pass the CIs.

### Was this patch authored or co-authored using generative AI tooling?

No.

Closes #50150 from dongjoon-hyun/SPARK-51387.

Authored-by: Dongjoon Hyun <dongjoon@apache.org>
Signed-off-by: Dongjoon Hyun <dongjoon@apache.org>
(cherry picked from commit 3d949af)
Signed-off-by: Dongjoon Hyun <dongjoon@apache.org>
dongjoon-hyun added a commit to dongjoon-hyun/spark that referenced this pull request Mar 5, 2025
### What changes were proposed in this pull request?

This PR aims to Upgrade Netty to 4.1.119.Final.

### Why are the changes needed?

- https://github.com/netty/netty/milestone/309?closed=1
  - netty/netty#14855
  - netty/netty#14830
  - netty/netty#14816
  - netty/netty#14810

### Does this PR introduce _any_ user-facing change?

No behavior change.

### How was this patch tested?

Pass the CIs.

### Was this patch authored or co-authored using generative AI tooling?

No.

Closes apache#50150 from dongjoon-hyun/SPARK-51387.

Authored-by: Dongjoon Hyun <dongjoon@apache.org>
Signed-off-by: Dongjoon Hyun <dongjoon@apache.org>
(cherry picked from commit 3d949af)
Signed-off-by: Dongjoon Hyun <dongjoon@apache.org>
zifeif2 pushed a commit to zifeif2/spark that referenced this pull request Nov 14, 2025
### What changes were proposed in this pull request?

This PR aims to Upgrade Netty to 4.1.119.Final.

### Why are the changes needed?

- https://github.com/netty/netty/milestone/309?closed=1
  - netty/netty#14855
  - netty/netty#14830
  - netty/netty#14816
  - netty/netty#14810

### Does this PR introduce _any_ user-facing change?

No behavior change.

### How was this patch tested?

Pass the CIs.

### Was this patch authored or co-authored using generative AI tooling?

No.

Closes apache#50150 from dongjoon-hyun/SPARK-51387.

Authored-by: Dongjoon Hyun <dongjoon@apache.org>
Signed-off-by: Dongjoon Hyun <dongjoon@apache.org>
(cherry picked from commit e84c345)
Signed-off-by: Dongjoon Hyun <dongjoon@apache.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants