Skip to content

Commit 710514b

Browse files
authored
Validate Merkle proofs and updates in TLB validate (#1479)
* Validate Merkle proofs and updates in TLB validate * Fix out-of-bound access in tl_jni_object.cpp
1 parent 987c7ca commit 710514b

File tree

4 files changed

+11
-4
lines changed

4 files changed

+11
-4
lines changed

crypto/block/block.tlb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ transaction$0111 account_addr:bits256 lt:uint64
296296
total_fees:CurrencyCollection state_update:^(HASH_UPDATE Account)
297297
description:^TransactionDescr = Transaction;
298298

299-
!merkle_update#02 {X:Type} old_hash:bits256 new_hash:bits256
299+
!merkle_update#04 {X:Type} old_hash:bits256 new_hash:bits256 old_depth:uint16 new_depth:uint16
300300
old:^X new:^X = MERKLE_UPDATE X;
301301
update_hashes#72 {X:Type} old_hash:bits256 new_hash:bits256
302302
= HASH_UPDATE X;

crypto/tl/tlbc-gen-cpp.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2074,7 +2074,7 @@ void CppTypeCode::generate_skip_field(const Constructor& constr, const Field& fi
20742074
output_cpp_expr(ss, expr, 100);
20752075
ss << '.';
20762076
}
2077-
ss << "validate_skip_ref(ops, cs, weak)" << tail;
2077+
ss << "validate_skip_ref(ops, cs, " << (constr.is_special ? "true" : "weak") << ")" << tail;
20782078
actions += Action{ss.str()};
20792079
}
20802080

crypto/tl/tlblib.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,13 @@ bool TLB::validate_ref_internal(int* ops, Ref<vm::Cell> cell_ref, bool weak) con
133133
}
134134
bool is_special;
135135
auto cs = load_cell_slice_special(std::move(cell_ref), is_special);
136-
return always_special() ? is_special : (is_special ? weak : (validate_skip(ops, cs) && cs.empty_ext()));
136+
if (cs.special_type() == vm::Cell::SpecialType::PrunnedBranch && weak) {
137+
return true;
138+
}
139+
if (always_special() != is_special) {
140+
return false;
141+
}
142+
return validate_skip(ops, cs, weak) && cs.empty_ext();
137143
}
138144

139145
bool TLB::print_skip(PrettyPrinter& pp, vm::CellSlice& cs) const {

tl/tl/tl_jni_object.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,9 @@ static size_t get_utf8_from_utf16_length(const jchar *p, jsize len) {
115115
for (jsize i = 0; i < len; i++) {
116116
unsigned int cur = p[i];
117117
if ((cur & 0xF800) == 0xD800) {
118+
++i;
118119
if (i < len) {
119-
unsigned int next = p[++i];
120+
unsigned int next = p[i];
120121
if ((next & 0xFC00) == 0xDC00 && (cur & 0x400) == 0) {
121122
result += 4;
122123
continue;

0 commit comments

Comments
 (0)