tx.file: new check_data_size() function
This commit is contained in:
parent
6cf721632c
commit
92d11b011b
1 changed files with 7 additions and 7 deletions
|
|
@ -32,6 +32,11 @@ class txfile_json_encoder(json.JSONEncoder):
|
|||
else:
|
||||
return json.JSONEncoder.default(self, o)
|
||||
|
||||
def check_data_size(cfg, data):
|
||||
if len(data) > cfg.max_tx_file_size:
|
||||
die('MaxFileSizeExceeded',
|
||||
f'{len(data)} bytes: transaction file size exceeds limit ({cfg.max_tx_file_size} bytes)')
|
||||
|
||||
def txfile_json_dumps(data):
|
||||
return json.dumps(data, separators = (',', ':'), cls=txfile_json_encoder)
|
||||
|
||||
|
|
@ -89,9 +94,7 @@ class MMGenTxFile(MMGenObject):
|
|||
tx = self.tx
|
||||
from ..fileutil import get_data_from_file
|
||||
data = get_data_from_file(tx.cfg, infile, desc=f'{tx.desc} data', quiet=quiet_open)
|
||||
if len(data) > tx.cfg.max_tx_file_size:
|
||||
die('MaxFileSizeExceeded',
|
||||
f'Transaction file size exceeds limit ({tx.cfg.max_tx_file_size} bytes)')
|
||||
check_data_size(tx.cfg, data)
|
||||
return (
|
||||
self.parse_data_json if data[0] == '{' else
|
||||
self.parse_data_legacy)(data, infile, get_proto_only)
|
||||
|
|
@ -322,10 +325,7 @@ class MMGenTxFile(MMGenObject):
|
|||
return '{{"{}":{},"chksum":"{}"}}'.format(self.data_label, data, make_chksum_6(data))
|
||||
|
||||
fmt_data = {'json': format_data_json, 'legacy': format_data_legacy}[tx.file_format]()
|
||||
|
||||
if len(fmt_data) > tx.cfg.max_tx_file_size:
|
||||
die('MaxFileSizeExceeded', f'Transaction file size exceeds limit ({tx.cfg.max_tx_file_size} bytes)')
|
||||
|
||||
check_data_size(tx.cfg, fmt_data)
|
||||
return fmt_data
|
||||
|
||||
def write(self, *,
|
||||
|
|
|
|||
Loading…
Reference in a new issue