Skip to content

Commit

Permalink
Test for recursion depth earlier so we can return an appropriate erro…
Browse files Browse the repository at this point in the history
…r and keep

the correct pairing between PushLimit and PopLimit calls.

Also, fix a lint error.

PiperOrigin-RevId: 485608890
  • Loading branch information
protobuf-github-bot authored and copybara-github committed Nov 2, 2022
1 parent 42cc7c6 commit 54cd586
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/google/protobuf/parse_context.cc
Original file line number Diff line number Diff line change
Expand Up @@ -265,12 +265,12 @@ const char* EpsCopyInputStream::InitFrom(io::ZeroCopyInputStream* zcis) {
const char* ParseContext::ReadSizeAndPushLimitAndDepth(const char* ptr,
int* old_limit) {
int size = ReadSize(&ptr);
if (PROTOBUF_PREDICT_FALSE(!ptr)) {
if (PROTOBUF_PREDICT_FALSE(!ptr) || depth_ <= 0) {
*old_limit = 0; // Make sure this isn't uninitialized even on error return
return nullptr;
}
*old_limit = PushLimit(ptr, size);
if (--depth_ < 0) return nullptr;
--depth_;
return ptr;
}

Expand Down Expand Up @@ -636,7 +636,7 @@ PROTOBUF_ALWAYS_INLINE inline V1Type ValueBarrier(V1Type value1) {

PROTOBUF_ALWAYS_INLINE inline uint64_t ExtractAndMergeTwoChunks(
uint64_t data, uint64_t first_byte) {
GOOGLE_DCHECK(first_byte <= 6);
GOOGLE_DCHECK_LE(first_byte, 6);
uint64_t first = Ubfx7(data, first_byte * 8);
uint64_t second = Ubfx7(data, (first_byte + 1) * 8);
return ForceToRegister(first | (second << 7));
Expand Down

0 comments on commit 54cd586

Please sign in to comment.