Skip to content

Negative byte values not properly converted to unsigned int in URI encoding #24413

@Andy-2639

Description

@Andy-2639

Affects: 5.2.0-Release, current master (2020-01-22)

Line numbers from 5.2.0.
spring-web/src/main/java/org/springframework/web/util/HierarchicalUriComponents.java:330

		for (byte b : bytes) {
			if (b < 0) {
				b += 256;
			}
			if (type.isAllowed(b)) {
				bos.write(b);
			}
		[...]

The b += 256 is a no-op as b is a byte (and so everything is modulo 256).
type.isAllowed(b) expects an int as argument --> a negative b is widened to a negative int value.

Proposed fix: change the data type of b from byte to int.

Metadata

Metadata

Assignees

Labels

in: webIssues in web modules (web, webmvc, webflux, websocket)type: bugA general bug

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions