You've already forked godot
mirror of
https://github.com/godotengine/godot.git
synced 2025-11-05 12:10:55 +00:00
[3.x] Core: Add recursion level check for Array and Dictionary hashing
(cherry picked from commit 68e8c1bb8f)
This commit is contained in:
committed by
Rémi Verschelde
parent
42bf1ef3fe
commit
b884fe2c76
@@ -117,16 +117,25 @@ bool Array::operator==(const Array &p_array) const {
|
||||
}
|
||||
|
||||
uint32_t Array::hash() const {
|
||||
return recursive_hash(0);
|
||||
}
|
||||
|
||||
uint32_t Array::recursive_hash(int p_recursion_count) const {
|
||||
ERR_FAIL_COND_V_MSG(p_recursion_count > MAX_RECURSION, 0, "Max recursion reached");
|
||||
p_recursion_count++;
|
||||
|
||||
uint32_t h = hash_djb2_one_32(0);
|
||||
|
||||
for (int i = 0; i < _p->array.size(); i++) {
|
||||
h = hash_djb2_one_32(_p->array[i].hash(), h);
|
||||
h = hash_djb2_one_32(_p->array[i].recursive_hash(p_recursion_count), h);
|
||||
}
|
||||
return h;
|
||||
}
|
||||
|
||||
void Array::operator=(const Array &p_array) {
|
||||
_ref(p_array);
|
||||
}
|
||||
|
||||
void Array::push_back(const Variant &p_value) {
|
||||
_p->array.push_back(p_value);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user