object-introspection/test/integration/thrift_isset.toml
Jake Hillion 7de35863f5 tbv2: fix Thrift isset lookups with padding
Thrift isset was failing with a SEGV if the struct contained padding. This is
because we indexed the `isset_indexes` data structure using our field index
rather than the index of the field in Thrift. This then gave a rubbish index
for any exceeding which happens if we have added padding in the middle of the
struct, and this index was looked up in the bitset which can cause a SEGV.

Track a new index `thriftFieldIdx` which is only incremented if we've looked up
a Thrift index.

Namespaced the generated Thrift structs while I was there. This isn't necessary
anymore but cleans things up.

Test plan:
- Added a test case with lots of padding. These don't run in the CI but it
  passes locally.
- `FILTER='OilIntegration.*' make test` - no failures
- `FILTER='OidIntegration.*' make test` - no new failures
2024-01-19 19:16:46 +00:00

370 lines
13 KiB
TOML

thrift_definitions = '''
namespace cpp2 ns_thrift_isset
include "thrift/annotation/cpp.thrift"
include "thrift/annotation/thrift.thrift"
struct MyThriftStructUnpacked {
1: optional i32 a;
2: optional i32 b;
3: optional i32 c;
}
struct MyThriftStructUnpackedPadded {
1: optional i32 a;
2: optional i64 b;
3: optional i32 c;
4: optional i64 d;
5: optional i32 e;
6: optional i64 f;
7: optional i32 g;
8: optional i64 h;
13: optional i32 i;
}
@cpp.PackIsset
struct MyThriftStructPacked {
1: optional i32 a;
2: optional i32 b;
3: optional i32 c;
4: optional i32 d;
5: optional i32 e;
6: optional i32 f;
7: optional i32 g;
8: optional i32 h;
9: optional i32 i;
10: optional i32 j;
}
@cpp.PackIsset{atomic = false}
struct MyThriftStructPackedNonAtomic {
1: optional i32 a;
2: optional i32 b;
3: optional i32 c;
4: optional i32 d;
}
struct MyThriftStructOutOfOrder {
3: i32 a;
1: i32 b;
2: i32 c;
}
struct MyThriftStructRequired {
1: required i32 a;
2: optional i32 b;
3: optional i32 c;
4: required i32 d;
5: required i32 e;
6: optional i32 f;
}
struct MyThriftStructBoxed {
@cpp.Ref{type = cpp.RefType.Unique}
1: optional i32 a;
@thrift.Box
2: optional i32 b;
3: optional i32 c;
4: optional i32 d;
5: optional i32 e;
}
'''
raw_definitions = '''
namespace ns_thrift_isset {
MyThriftStructBoxed::MyThriftStructBoxed() :
__fbthrift_field_b(),
__fbthrift_field_c(),
__fbthrift_field_d(),
__fbthrift_field_e() {
}
MyThriftStructBoxed::~MyThriftStructBoxed() {}
MyThriftStructBoxed::MyThriftStructBoxed(MyThriftStructBoxed&& other) noexcept :
__fbthrift_field_a(std::move(other.__fbthrift_field_a)),
__fbthrift_field_b(std::move(other.__fbthrift_field_b)),
__fbthrift_field_c(std::move(other.__fbthrift_field_c)),
__fbthrift_field_d(std::move(other.__fbthrift_field_d)),
__fbthrift_field_e(std::move(other.__fbthrift_field_e)),
__isset(other.__isset) {
}
} // namespace ns_thrift_isset
'''
[cases]
[cases.unpacked]
param_types = ["const MyThriftStructUnpacked&"]
setup = '''
MyThriftStructUnpacked ret;
ret.a_ref() = 1;
ret.c_ref() = 1;
return ret;
'''
features = ["capture-thrift-isset"]
expect_json = '''[{
"staticSize":16,
"dynamicSize":0,
"members":[
{"name":"__fbthrift_field_a", "staticSize":4, "isset":true},
{"name":"__fbthrift_field_b", "staticSize":4, "isset":false},
{"name":"__fbthrift_field_c", "staticSize":4, "isset":true},
{"name":"__isset", "staticSize":3}
]}]'''
expect_json_v2 = '''[{
"staticSize":16,
"exclusiveSize":1,
"size":16,
"members":[
{"name":"__fbthrift_field_a", "staticSize":4, "is_set":true},
{"name":"__fbthrift_field_b", "staticSize":4, "is_set":false},
{"name":"__fbthrift_field_c", "staticSize":4, "is_set":true},
{"name":"__isset", "staticSize":3, "NOT":"is_set"}
]
}]'''
[cases.unpacked_padded]
param_types = ["const MyThriftStructUnpackedPadded&"]
setup = '''
MyThriftStructUnpackedPadded ret;
ret.a_ref() = 1;
ret.c_ref() = 1;
return ret;
'''
features = ["capture-thrift-isset"]
expect_json = '''[{
"staticSize":80,
"dynamicSize":0,
"members":[
{"name":"__fbthrift_field_a", "staticSize":4, "isset":true},
{"name":"__fbthrift_field_b", "staticSize":8, "isset":false},
{"name":"__fbthrift_field_c", "staticSize":4, "isset":true},
{"name":"__fbthrift_field_d", "staticSize":8, "isset":false},
{"name":"__fbthrift_field_e", "staticSize":4, "isset":false},
{"name":"__fbthrift_field_f", "staticSize":8, "isset":false},
{"name":"__fbthrift_field_g", "staticSize":4, "isset":false},
{"name":"__fbthrift_field_h", "staticSize":8, "isset":false},
{"name":"__fbthrift_field_i", "staticSize":4, "isset":false},
{"name":"__isset", "staticSize":9}
]}]'''
expect_json_v2 = '''[{
"staticSize":80,
"exclusiveSize":19,
"size":80,
"members":[
{"name":"__fbthrift_field_a", "staticSize":4, "is_set":true},
{"name":"__fbthrift_field_b", "staticSize":8, "is_set":false},
{"name":"__fbthrift_field_c", "staticSize":4, "is_set":true},
{"name":"__fbthrift_field_d", "staticSize":8, "is_set":false},
{"name":"__fbthrift_field_e", "staticSize":4, "is_set":false},
{"name":"__fbthrift_field_f", "staticSize":8, "is_set":false},
{"name":"__fbthrift_field_g", "staticSize":4, "is_set":false},
{"name":"__fbthrift_field_h", "staticSize":8, "is_set":false},
{"name":"__fbthrift_field_i", "staticSize":4, "is_set":false},
{"name":"__isset", "staticSize":9, "NOT":"is_set"}
]
}]'''
[cases.packed]
param_types = ["const MyThriftStructPacked&"]
setup = '''
MyThriftStructPacked ret;
ret.a_ref() = 1;
ret.c_ref() = 1;
ret.d_ref() = 1;
ret.g_ref() = 1;
ret.h_ref() = 1;
ret.j_ref() = 1;
return ret;
'''
features = ["capture-thrift-isset"]
expect_json = '''[{
"staticSize":44,
"dynamicSize":0,
"members":[
{"name":"__fbthrift_field_a", "staticSize":4, "isset":true},
{"name":"__fbthrift_field_b", "staticSize":4, "isset":false},
{"name":"__fbthrift_field_c", "staticSize":4, "isset":true},
{"name":"__fbthrift_field_d", "staticSize":4, "isset":true},
{"name":"__fbthrift_field_e", "staticSize":4, "isset":false},
{"name":"__fbthrift_field_f", "staticSize":4, "isset":false},
{"name":"__fbthrift_field_g", "staticSize":4, "isset":true},
{"name":"__fbthrift_field_h", "staticSize":4, "isset":true},
{"name":"__fbthrift_field_i", "staticSize":4, "isset":false},
{"name":"__fbthrift_field_j", "staticSize":4, "isset":true},
{"name":"__isset", "staticSize":2}
]}]'''
expect_json_v2 = '''[{
"staticSize":44,
"exclusiveSize":2,
"size":44,
"members":[
{"name":"__fbthrift_field_a", "staticSize":4, "is_set":true},
{"name":"__fbthrift_field_b", "staticSize":4, "is_set":false},
{"name":"__fbthrift_field_c", "staticSize":4, "is_set":true},
{"name":"__fbthrift_field_d", "staticSize":4, "is_set":true},
{"name":"__fbthrift_field_e", "staticSize":4, "is_set":false},
{"name":"__fbthrift_field_f", "staticSize":4, "is_set":false},
{"name":"__fbthrift_field_g", "staticSize":4, "is_set":true},
{"name":"__fbthrift_field_h", "staticSize":4, "is_set":true},
{"name":"__fbthrift_field_i", "staticSize":4, "is_set":false},
{"name":"__fbthrift_field_j", "staticSize":4, "is_set":true},
{"name":"__isset", "staticSize":2, "NOT":"is_set"}
]}]'''
[cases.packed_non_atomic]
param_types = ["const MyThriftStructPackedNonAtomic&"]
setup = '''
MyThriftStructPackedNonAtomic ret;
ret.a_ref() = 1;
ret.c_ref() = 1;
return ret;
'''
features = ["capture-thrift-isset"]
expect_json = '''[{
"staticSize":20,
"dynamicSize":0,
"members":[
{"name":"__fbthrift_field_a", "staticSize":4, "isset":true},
{"name":"__fbthrift_field_b", "staticSize":4, "isset":false},
{"name":"__fbthrift_field_c", "staticSize":4, "isset":true},
{"name":"__fbthrift_field_d", "staticSize":4, "isset":false},
{"name":"__isset", "staticSize":1}
]}]'''
expect_json_v2 = '''[{
"staticSize":20,
"exclusiveSize":3,
"size":20,
"members":[
{"name":"__fbthrift_field_a", "staticSize":4, "is_set":true},
{"name":"__fbthrift_field_b", "staticSize":4, "is_set":false},
{"name":"__fbthrift_field_c", "staticSize":4, "is_set":true},
{"name":"__fbthrift_field_d", "staticSize":4, "is_set":false},
{"name":"__isset", "staticSize":1, "NOT":"is_set"}
]}]'''
[cases.out_of_order]
param_types = ["const MyThriftStructOutOfOrder&"]
setup = '''
MyThriftStructOutOfOrder ret;
ret.b_ref() = 1;
return ret;
'''
features = ["capture-thrift-isset"]
expect_json = '''[{
"staticSize":16,
"dynamicSize":0,
"members":[
{"name":"__fbthrift_field_a", "staticSize":4, "isset":false},
{"name":"__fbthrift_field_b", "staticSize":4, "isset":true},
{"name":"__fbthrift_field_c", "staticSize":4, "isset":false},
{"name":"__isset", "staticSize":3}
]}]'''
expect_json_v2 = '''[{
"staticSize":16,
"exclusiveSize":1,
"size":16,
"members":[
{"name":"__fbthrift_field_a", "staticSize":4, "is_set":false},
{"name":"__fbthrift_field_b", "staticSize":4, "is_set":true},
{"name":"__fbthrift_field_c", "staticSize":4, "is_set":false},
{"name":"__isset", "staticSize":3, "NOT":"is_set"}
]}]'''
[cases.required]
param_types = ["const MyThriftStructRequired&"]
setup = '''
MyThriftStructRequired ret;
ret.b_ref() = 1;
ret.f_ref() = 1;
return ret;
'''
features = ["capture-thrift-isset"]
expect_json = '''[{
"staticSize":28,
"dynamicSize":0,
"members":[
{"name":"__fbthrift_field_a", "staticSize":4, "NOT":"isset"},
{"name":"__fbthrift_field_b", "staticSize":4, "isset":true},
{"name":"__fbthrift_field_c", "staticSize":4, "isset":false},
{"name":"__fbthrift_field_d", "staticSize":4, "NOT":"isset"},
{"name":"__fbthrift_field_e", "staticSize":4, "NOT":"isset"},
{"name":"__fbthrift_field_f", "staticSize":4, "isset":true},
{"name":"__isset", "staticSize":3}
]}]'''
expect_json_v2 = '''[{
"staticSize":28,
"exclusiveSize":1,
"size":28,
"members":[
{"name":"__fbthrift_field_a", "staticSize":4, "NOT":"is_set"},
{"name":"__fbthrift_field_b", "staticSize":4, "is_set":true},
{"name":"__fbthrift_field_c", "staticSize":4, "is_set":false},
{"name":"__fbthrift_field_d", "staticSize":4, "NOT":"is_set"},
{"name":"__fbthrift_field_e", "staticSize":4, "NOT":"is_set"},
{"name":"__fbthrift_field_f", "staticSize":4, "is_set":true},
{"name":"__isset", "staticSize":3, "NOT":"is_set"}
]}]'''
[cases.box]
param_types = ["const MyThriftStructBoxed&"]
setup = '''
MyThriftStructBoxed ret;
ret.d_ref() = 1;
ret.e_ref() = 1;
return ret;
'''
features = ["capture-thrift-isset"]
expect_json = '''[{
"staticSize":32,
"dynamicSize":0,
"members":[
{"name":"__fbthrift_field_a", "staticSize":8, "NOT":"isset"},
{"name":"__fbthrift_field_b", "staticSize":8, "NOT":"isset"},
{"name":"__fbthrift_field_c", "staticSize":4, "isset":false},
{"name":"__fbthrift_field_d", "staticSize":4, "isset":true},
{"name":"__fbthrift_field_e", "staticSize":4, "isset":true},
{"name":"__isset", "staticSize":3}
]}]'''
expect_json_v2 = '''[{
"staticSize":32,
"exclusiveSize":1,
"size":32,
"members":[
{"name":"__fbthrift_field_a", "staticSize":8, "NOT":"is_set"},
{"name":"__fbthrift_field_b", "staticSize":8, "NOT":"is_set"},
{"name":"__fbthrift_field_c", "staticSize":4, "is_set":false},
{"name":"__fbthrift_field_d", "staticSize":4, "is_set":true},
{"name":"__fbthrift_field_e", "staticSize":4, "is_set":true},
{"name":"__isset", "staticSize":3, "NOT":"is_set"}
]}]'''
[cases.no_capture]
param_types = ["const MyThriftStructBoxed&"]
setup = '''
MyThriftStructBoxed ret;
ret.d_ref() = 1;
ret.e_ref() = 1;
return ret;
'''
expect_json = '''[{
"staticSize":32,
"dynamicSize":0,
"members":[
{"name":"__fbthrift_field_a", "staticSize":8, "NOT":"isset"},
{"name":"__fbthrift_field_b", "staticSize":8, "NOT":"isset"},
{"name":"__fbthrift_field_c", "staticSize":4, "NOT":"isset"},
{"name":"__fbthrift_field_d", "staticSize":4, "NOT":"isset"},
{"name":"__fbthrift_field_e", "staticSize":4, "NOT":"isset"},
{"name":"__isset", "staticSize":3}
]}]'''
expect_json_v2 = '''[{
"staticSize":32,
"exclusiveSize":1,
"size":32,
"members":[
{"name":"__fbthrift_field_a", "staticSize":8, "NOT":"is_set"},
{"name":"__fbthrift_field_b", "staticSize":8, "NOT":"is_set"},
{"name":"__fbthrift_field_c", "staticSize":4, "NOT":"is_set"},
{"name":"__fbthrift_field_d", "staticSize":4, "NOT":"is_set"},
{"name":"__fbthrift_field_e", "staticSize":4, "NOT":"is_set"},
{"name":"__isset", "staticSize":3, "NOT":"is_set"}
]}]'''