Skip to content

A JSON serialization exception can lead to corrupted output being written to the OutputStream of the response. #33358

Closed as not planned
@light0x00

Description

@light0x00

Affects: 5.3.31

Happening in the phrase of writing object returned by endpoint(controller method) to the OutputStream of response body.

image

When the ObjectWriter#writeValue(JsonGenerator g, Object value) throw exception, eg: due to a null key of HashMap:

image

In such case, theObjectWriter#close method will be called( invoke by the try-resources statement), it will write the intermediate corrupted result to the OutputStream.

image

Whereafter, the DispatcherServlet#processDispatchResult method will trigger HandlerExceptionResolver, which will cause a secondary writing.

image

Stand in the perspective of the client, a corrupted response they will get.

{"success":true,"data":{}}{"success":false}

The {"success":true,"data":{}} written by ObjectWriter#close, and the {"success":false} written by HandlerExceptionResolver.

Metadata

Metadata

Assignees

No one assigned

    Labels

    in: webIssues in web modules (web, webmvc, webflux, websocket)status: duplicateA duplicate of another issue

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions