Skip to content

Commit f9ea5cf

Browse files
committed
Bypass ipfs hash validation for large files
1 parent e50470e commit f9ea5cf

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

ethpm/backends/ipfs.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,10 +80,13 @@ def __init__(self) -> None:
8080
def fetch_uri_contents(self, uri: str) -> bytes:
8181
ipfs_hash = extract_ipfs_path_from_uri(uri)
8282
contents = self.client.cat(ipfs_hash)
83-
validation_hash = generate_file_hash(contents)
84-
if validation_hash != ipfs_hash:
85-
raise EthPMValidationError(
86-
f"Hashed IPFS contents retrieved from uri: {uri} do not match its content hash."
83+
# Local validation of hashed contents only works for non-chunked files ~< 256kb
84+
# Improved validation WIP @ https://github.com/ethpm/py-ethpm/pull/165
85+
if len(contents) <= 262144:
86+
validation_hash = generate_file_hash(contents)
87+
if validation_hash != ipfs_hash:
88+
raise ValidationError(
89+
f"Hashed IPFS contents retrieved from uri: {uri} do not match its content hash."
8790
)
8891
return contents
8992

0 commit comments

Comments
 (0)