Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update lite_unittest to pad varints before calling internal::VarintParse() #15151

Merged
1 commit merged into from
Dec 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/google/protobuf/lite_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
// Author: [email protected] (Kenton Varda)

#include <climits>
#include <cstdint>
#include <iostream>
#include <limits>
#include <string>
Expand Down Expand Up @@ -104,7 +105,7 @@ void SetSomeTypesInEmptyMessageUnknownFields(

TEST(ParseVarintTest, Varint32) {
auto test_value = [](uint32_t value, int varint_length) {
uint8_t buffer[10];
uint8_t buffer[10] = {0};
uint8_t* p = io::CodedOutputStream::WriteVarint32ToArray(value, buffer);
ASSERT_EQ(p - buffer, varint_length) << "Value = " << value;

Expand All @@ -131,7 +132,7 @@ TEST(ParseVarintTest, Varint32) {

TEST(ParseVarintTest, Varint64) {
auto test_value = [](uint64_t value, int varint_length) {
uint8_t buffer[10];
uint8_t buffer[10] = {0};
uint8_t* p = io::CodedOutputStream::WriteVarint64ToArray(value, buffer);
ASSERT_EQ(p - buffer, varint_length) << "Value = " << value;

Expand Down
1 change: 1 addition & 0 deletions src/google/protobuf/parse_context.h
Original file line number Diff line number Diff line change
Expand Up @@ -847,6 +847,7 @@ static const char* VarintParseSlowArm(const char* p, uint64_t* out,
}
#endif

// The caller must ensure that p points to at least 10 valid bytes.
template <typename T>
PROTOBUF_NODISCARD const char* VarintParse(const char* p, T* out) {
#if defined(__aarch64__) && defined(ABSL_IS_LITTLE_ENDIAN)
Expand Down
Loading