Merge remote-tracking branch 'origin/topic/etyp/fix-record-vec-type-conflict'

* origin/topic/etyp/fix-record-vec-type-conflict:
  Fix record coercion with compatible types
This commit is contained in:
Evan Typanski 2025-08-06 09:10:08 -04:00
commit 22f77248f5
7 changed files with 77 additions and 1 deletions

View file

@ -1,3 +1,9 @@
8.1.0-dev.12 | 2025-08-06 09:10:08 -0400
* GH-4722: Fix record coercion with compatible types (Evan Typanski, Corelight)
Fixes #4722
8.1.0-dev.10 | 2025-08-06 14:27:32 +0200
* TapAnalyzer: Fix docstring (Arne Welzel, Corelight)

View file

@ -1 +1 @@
8.1.0-dev.10
8.1.0-dev.12

View file

@ -2170,6 +2170,9 @@ bool record_promotion_compatible(const RecordType* super_rec, const RecordType*
if ( same_type(sub_field_type, super_field_type) )
continue;
if ( BothArithmetic(sub_field_type->Tag(), super_field_type->Tag()) )
continue;
if ( sub_field_type->Tag() != TYPE_RECORD )
return false;

View file

@ -0,0 +1,7 @@
### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63.
error in <...>/arithmetic-record-vec-fail.zeek, line 13 and int: type clash for field "a" ((coerce [$a=+1] to WithCount) and int)
error in <...>/arithmetic-record-vec-fail.zeek, line 13 and int: type clash for field "a" ((coerce [$a=-2] to WithCount) and int)
error in <...>/arithmetic-record-vec-fail.zeek, line 13 and double: type clash for field "a" ((coerce [$a=3.0] to WithCount) and double)
error in <...>/arithmetic-record-vec-fail.zeek, line 16 and double: type clash for field "a" ((coerce [$a=1.0] to WithInt) and double)
error in <...>/arithmetic-record-vec-fail.zeek, line 16 and double: type clash for field "a" ((coerce [$a=+2.0] to WithInt) and double)
error in <...>/arithmetic-record-vec-fail.zeek, line 16 and double: type clash for field "a" ((coerce [$a=-3.0] to WithInt) and double)

View file

@ -0,0 +1,7 @@
### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63.
[[a=1], [a=2], [a=3]]
[[a=1], [a=2], [a=3]]
[[a=1], [a=2], [a=3]]
[[a=1.0], [a=2.0], [a=3.0]]
[[a=1.0], [a=2.0], [a=3.0]]
[[a=1.0], [a=2.0], [a=-3.0]]

View file

@ -0,0 +1,16 @@
# @TEST-EXEC-FAIL: zeek -b %INPUT 2>err
# @TEST-EXEC: TEST_DIFF_CANONIFIER=$SCRIPTS/diff-remove-abspath btest-diff err
type WithCount: record {
a: count;
};
type WithInt: record {
a: int;
};
type CountRecVec: vector of WithCount;
global vec_count_fail = CountRecVec([$a=+1], [$a=-2], [$a=3.0]);
type IntRecVec: vector of WithInt;
global vec_int_fail = IntRecVec([$a=1.0], [$a=+2.0], [$a=-3.0]);

View file

@ -0,0 +1,37 @@
# @TEST-DOC: Ensures arithmetic type checking works when adding to vector; regression test for #4722
#
# @TEST-EXEC: zeek -b %INPUT >out
# @TEST-EXEC: btest-diff out
type WithCount: record {
a: count;
};
type WithInt: record {
a: int;
};
type WithDouble: record {
a: double;
};
type CountRecVec: vector of WithCount;
global vec_count = CountRecVec([$a=1], [$a=2], [$a=3]);
type IntRecVec: vector of WithInt;
global vec_int = IntRecVec([$a=+1], [$a=+2], [$a=+3]);
global vec_count_int = IntRecVec([$a=1], [$a=2], [$a=3]);
type DoubleRecVec: vector of WithDouble;
global vec_double = DoubleRecVec([$a=1.0], [$a=2.0], [$a=3.0]);
global vec_count_double = DoubleRecVec([$a=1], [$a=2], [$a=3]);
global vec_int_double = DoubleRecVec([$a=+1], [$a=+2], [$a=-3]);
print vec_count;
print vec_int;
print vec_count_int;
print vec_double;
print vec_count_double;
print vec_int_double;