mirror of
				https://github.com/ton-blockchain/ton
				synced 2025-03-09 15:40:10 +00:00 
			
		
		
		
	Merge pull request #479 from SpyCheese/testnet
Add validity checks to RLDP and c4/c5
This commit is contained in:
		
						commit
						f8cc01a5fe
					
				
					 4 changed files with 37 additions and 19 deletions
				
			
		| 
						 | 
				
			
			@ -503,7 +503,7 @@ int VmState::run() {
 | 
			
		|||
 | 
			
		||||
bool VmState::try_commit() {
 | 
			
		||||
  if (cr.d[0].not_null() && cr.d[1].not_null() && cr.d[0]->get_depth() <= max_data_depth &&
 | 
			
		||||
      cr.d[1]->get_depth() <= max_data_depth) {
 | 
			
		||||
      cr.d[1]->get_depth() <= max_data_depth && cr.d[0]->get_level() == 0 && cr.d[1]->get_level() == 0) {
 | 
			
		||||
    cstate.c4 = cr.d[0];
 | 
			
		||||
    cstate.c5 = cr.d[1];
 | 
			
		||||
    cstate.committed = true;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
							
								
								
									
										48
									
								
								fec/fec.cpp
									
										
									
									
									
								
							
							
						
						
									
										48
									
								
								fec/fec.cpp
									
										
									
									
									
								
							| 
						 | 
				
			
			@ -19,6 +19,7 @@
 | 
			
		|||
#include "fec.h"
 | 
			
		||||
#include "td/utils/overloaded.h"
 | 
			
		||||
#include "auto/tl/ton_api.hpp"
 | 
			
		||||
#include "td/utils/misc.h"
 | 
			
		||||
 | 
			
		||||
namespace ton {
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -98,24 +99,37 @@ td::uint32 FecType::symbol_size() const {
 | 
			
		|||
}
 | 
			
		||||
 | 
			
		||||
td::Result<FecType> FecType::create(tl_object_ptr<ton_api::fec_Type> obj) {
 | 
			
		||||
  td::int32 data_size_int, symbol_size_int, symbols_count_int;
 | 
			
		||||
  ton_api::downcast_call(*obj, td::overloaded([&](const auto &obj) {
 | 
			
		||||
    data_size_int = obj.data_size_;
 | 
			
		||||
    symbol_size_int = obj.symbol_size_;
 | 
			
		||||
    symbols_count_int = obj.symbols_count_;
 | 
			
		||||
  }));
 | 
			
		||||
  TRY_RESULT(data_size, td::narrow_cast_safe<size_t>(data_size_int));
 | 
			
		||||
  TRY_RESULT(symbol_size, td::narrow_cast_safe<size_t>(symbol_size_int));
 | 
			
		||||
  TRY_RESULT(symbols_count, td::narrow_cast_safe<size_t>(symbols_count_int));
 | 
			
		||||
 | 
			
		||||
  if (symbol_size == 0) {
 | 
			
		||||
    return td::Status::Error("invalid fec type: symbol_size is 0");
 | 
			
		||||
  }
 | 
			
		||||
  if (symbol_size > 1 << 11) {
 | 
			
		||||
    return td::Status::Error("invalid fec type: symbol_size is too big");
 | 
			
		||||
  }
 | 
			
		||||
  if (symbols_count != (data_size + symbol_size - 1) / symbol_size) {
 | 
			
		||||
    return td::Status::Error("invalid fec type: wrong symbols_count");
 | 
			
		||||
  }
 | 
			
		||||
  FecType T;
 | 
			
		||||
  ton_api::downcast_call(
 | 
			
		||||
      *obj.get(), td::overloaded(
 | 
			
		||||
                      [&](const ton_api::fec_raptorQ &obj) {
 | 
			
		||||
                        T.type_ = td::fec::RaptorQEncoder::Parameters{static_cast<size_t>(obj.data_size_),
 | 
			
		||||
                                                                      static_cast<size_t>(obj.symbol_size_),
 | 
			
		||||
                                                                      static_cast<size_t>(obj.symbols_count_)};
 | 
			
		||||
                      },
 | 
			
		||||
                      [&](const ton_api::fec_roundRobin &obj) {
 | 
			
		||||
                        T.type_ = td::fec::RoundRobinEncoder::Parameters{static_cast<size_t>(obj.data_size_),
 | 
			
		||||
                                                                         static_cast<size_t>(obj.symbol_size_),
 | 
			
		||||
                                                                         static_cast<size_t>(obj.symbols_count_)};
 | 
			
		||||
                      },
 | 
			
		||||
                      [&](const ton_api::fec_online &obj) {
 | 
			
		||||
                        T.type_ = td::fec::OnlineEncoder::Parameters{static_cast<size_t>(obj.data_size_),
 | 
			
		||||
                                                                     static_cast<size_t>(obj.symbol_size_),
 | 
			
		||||
                                                                     static_cast<size_t>(obj.symbols_count_)};
 | 
			
		||||
                      }));
 | 
			
		||||
  ton_api::downcast_call(*obj,
 | 
			
		||||
                         td::overloaded(
 | 
			
		||||
                             [&](const ton_api::fec_raptorQ &obj) {
 | 
			
		||||
                               T.type_ = td::fec::RaptorQEncoder::Parameters{data_size, symbol_size, symbols_count};
 | 
			
		||||
                             },
 | 
			
		||||
                             [&](const ton_api::fec_roundRobin &obj) {
 | 
			
		||||
                               T.type_ = td::fec::RoundRobinEncoder::Parameters{data_size, symbol_size, symbols_count};
 | 
			
		||||
                             },
 | 
			
		||||
                             [&](const ton_api::fec_online &obj) {
 | 
			
		||||
                               T.type_ = td::fec::OnlineEncoder::Parameters{data_size, symbol_size, symbols_count};
 | 
			
		||||
                             }));
 | 
			
		||||
  return T;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -28,8 +28,8 @@ td::Result<std::unique_ptr<BroadcastFec>> BroadcastFec::create(Overlay::Broadcas
 | 
			
		|||
                                                               Overlay::BroadcastDataHash data_hash, td::uint32 flags,
 | 
			
		||||
                                                               td::uint32 date, fec::FecType fec_type) {
 | 
			
		||||
  auto F = std::make_unique<BroadcastFec>(hash, std::move(src), data_hash, flags, date, std::move(fec_type));
 | 
			
		||||
  TRY_STATUS(F->init_fec_type());
 | 
			
		||||
  TRY_STATUS(F->run_checks());
 | 
			
		||||
  TRY_STATUS(F->init_fec_type());
 | 
			
		||||
  return std::move(F);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -125,6 +125,10 @@ void RldpTransferReceiverImpl::receive_part(fec::FecType fec_type, td::uint32 pa
 | 
			
		|||
  }
 | 
			
		||||
 | 
			
		||||
  if (!decoder_) {
 | 
			
		||||
    if (offset_ + fec_type.size() > total_size_) {
 | 
			
		||||
      VLOG(RLDP_NOTICE) << "failed to create decoder: data size in fec type is too big";
 | 
			
		||||
      return;
 | 
			
		||||
    }
 | 
			
		||||
    auto D = fec_type.create_decoder();
 | 
			
		||||
    if (D.is_error()) {
 | 
			
		||||
      VLOG(RLDP_WARNING) << "failed to create decoder: " << D.move_as_error();
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue