Skip to content

Commit bd2c681

Browse files
committed
Add 2 bounds checks in ProtobufParser
1 parent 2778eb7 commit bd2c681

1 file changed

Lines changed: 12 additions & 0 deletions

File tree

protobuf/src/main/java/tools/jackson/dataformat/protobuf/ProtobufParser.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -570,6 +570,12 @@ public JsonToken nextToken() throws JacksonException
570570

571571
int len = _decodeLength();
572572
int newEnd = _inputPtr + len;
573+
// Guard against integer overflow: _inputPtr and len are both non-negative,
574+
// so a result smaller than _inputPtr means the sum wrapped.
575+
if (newEnd < _inputPtr) {
576+
_reportErrorF("Packed array length overflows for field '%s': ptr=%d, len=%d",
577+
_currentField.name, _inputPtr, len);
578+
}
573579

574580
// First: validate that we do not extend past end offset of enclosing message
575581
if (!_streamReadContext.inRoot()) {
@@ -881,6 +887,12 @@ private JsonToken _readNextValue(FieldType t, int nextState) throws JacksonExcep
881887
_currentMessage = msg;
882888
int len = _decodeLength();
883889
int newEnd = _inputPtr + len;
890+
// Guard against integer overflow: _inputPtr and len are both non-negative,
891+
// so a result smaller than _inputPtr means the sum wrapped.
892+
if (newEnd < _inputPtr) {
893+
_reportErrorF("Message length overflows for field '%s': ptr=%d, len=%d",
894+
_currentField.name, _inputPtr, len);
895+
}
884896

885897
// First: validate that we do not extend past end offset of enclosing message
886898
if (newEnd > _currentEndOffset) {

0 commit comments

Comments
 (0)