Skip to content

Commit

Permalink
Check index bounds in compact protocol reader. (rapidsai#16493)
Browse files Browse the repository at this point in the history
This adds bounds checking to the compact protocol reader's read function.

Authors:
  - Bradley Dice (https://github.com/bdice)

Approvers:
  - David Wendt (https://github.com/davidwendt)
  - Nghia Truong (https://github.com/ttnghia)
  - Muhammad Haseeb (https://github.com/mhaseeb123)

URL: rapidsai#16493
  • Loading branch information
bdice authored Sep 7, 2024
1 parent aa08fdb commit 4784067
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions cpp/src/io/parquet/compact_protocol_reader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ struct parquet_field_bool_list : public parquet_field_list<bool, FieldType::BOOL
auto const read_value = [&val = v](uint32_t i, CompactProtocolReader* cpr) {
auto const current_byte = cpr->getb();
assert_bool_field_type(current_byte);
CUDF_EXPECTS(i < val.size(), "Index out of bounds");
val[i] = current_byte == static_cast<int>(FieldType::BOOLEAN_TRUE);
};
bind_read_func(read_value);
Expand Down Expand Up @@ -189,6 +190,7 @@ struct parquet_field_int_list : public parquet_field_list<T, EXPECTED_TYPE> {
parquet_field_int_list(int f, std::vector<T>& v) : parquet_field_list<T, EXPECTED_TYPE>(f, v)
{
auto const read_value = [&val = v](uint32_t i, CompactProtocolReader* cpr) {
CUDF_EXPECTS(i < val.size(), "Index out of bounds");
val[i] = cpr->get_zigzag<T>();
};
this->bind_read_func(read_value);
Expand Down Expand Up @@ -233,6 +235,7 @@ struct parquet_field_string_list : public parquet_field_list<std::string, FieldT
auto const l = cpr->get_u32();
CUDF_EXPECTS(l < static_cast<size_t>(cpr->m_end - cpr->m_cur), "string length mismatch");

CUDF_EXPECTS(i < val.size(), "Index out of bounds");
val[i].assign(reinterpret_cast<char const*>(cpr->m_cur), l);
cpr->m_cur += l;
};
Expand Down Expand Up @@ -270,6 +273,7 @@ struct parquet_field_enum_list : public parquet_field_list<Enum, FieldType::I32>
: parquet_field_list<Enum, FieldType::I32>(f, v)
{
auto const read_value = [&val = v](uint32_t i, CompactProtocolReader* cpr) {
CUDF_EXPECTS(i < val.size(), "Index out of bounds");
val[i] = static_cast<Enum>(cpr->get_i32());
};
this->bind_read_func(read_value);
Expand Down Expand Up @@ -355,6 +359,7 @@ struct parquet_field_struct_list : public parquet_field_list<T, FieldType::STRUC
: parquet_field_list<T, FieldType::STRUCT>(f, v)
{
auto const read_value = [&val = v](uint32_t i, CompactProtocolReader* cpr) {
CUDF_EXPECTS(i < val.size(), "Index out of bounds");
cpr->read(&val[i]);
};
this->bind_read_func(read_value);
Expand Down Expand Up @@ -399,6 +404,7 @@ struct parquet_field_binary_list
auto const l = cpr->get_u32();
CUDF_EXPECTS(l <= static_cast<size_t>(cpr->m_end - cpr->m_cur), "binary length mismatch");

CUDF_EXPECTS(i < val.size(), "Index out of bounds");
val[i].resize(l);
val[i].assign(cpr->m_cur, cpr->m_cur + l);
cpr->m_cur += l;
Expand Down

0 comments on commit 4784067

Please sign in to comment.