From c4c5f57f3251a7cbb301c568e818d68072984331 Mon Sep 17 00:00:00 2001 From: Nick Gheorghita Date: Fri, 19 Jul 2019 09:31:52 -0600 Subject: [PATCH] Bypass ipfs hash validation for large files --- ethpm/backends/ipfs.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/ethpm/backends/ipfs.py b/ethpm/backends/ipfs.py index 6d42ab7db8..1cf2d4104b 100644 --- a/ethpm/backends/ipfs.py +++ b/ethpm/backends/ipfs.py @@ -80,11 +80,14 @@ def __init__(self) -> None: def fetch_uri_contents(self, uri: str) -> bytes: ipfs_hash = extract_ipfs_path_from_uri(uri) contents = self.client.cat(ipfs_hash) - validation_hash = generate_file_hash(contents) - if validation_hash != ipfs_hash: - raise EthPMValidationError( - f"Hashed IPFS contents retrieved from uri: {uri} do not match its content hash." - ) + # Local validation of hashed contents only works for non-chunked files ~< 256kb + # Improved validation WIP @ https://github.com/ethpm/py-ethpm/pull/165 + if len(contents) <= 262144: + validation_hash = generate_file_hash(contents) + if validation_hash != ipfs_hash: + raise EthPMValidationError( + f"Hashed IPFS contents retrieved from uri: {uri} do not match its content hash." + ) return contents @property