ethereum / hexbytes

Python `bytes` subclass that decodes hex, with a readable console output
MIT License
27 stars 19 forks source link

Very large values cause recursion error during `__getitem__` #33

Open antazoey opened 1 year ago

antazoey commented 1 year ago

What happened?

I would expect the same behavior from accessing from large native bytes compared to HexBytes. However, HexBytes.__getitem__ may potentially cause recursion errors.

Code that produced the error

HexBytes("0" * 1000000000000)

# but also really is coming from struct logs in debug_tt

Full error output

RecursionError: maximum recursion depth exceeded while calling a Python object

### Fill this section in if you know how this could or should be fixed

_No response_

### hexbytes Version

0.3.0

### Python Version

3.9.13

### Operating System

macos

### Output from pip-freeze

```shell
<all my editable ape installs>
appnope==0.1.3
argcomplete==2.0.0
arrow==1.2.3
asgiref==3.6.0
astroid==2.9.3
asttokens==2.2.1
async-timeout==4.0.2
asyncio==3.4.3
attrs==23.1.0
-e git+ssh://git@github.com/unparalleled-js/audius-py.git@a5260a6290b1b02589a87335af22304257b1b2bc#egg=audius
-e git+ssh://git@github.com/unparalleled-js/audius-py.git@a5260a6290b1b02589a87335af22304257b1b2bc#egg=audius_py
Babel==2.10.3
backcall==0.2.0
bandit==1.7.4
base58==1.0.3
basedmypy==1.5.0
basedtyping==0.0.1
beautifulsoup4==4.11.1
bech32==1.2.0
binaryornot==0.4.4
bitarray==2.7.4
bitcoin==1.1.42
bitstring==3.1.9
black==23.3.0
bleach==6.0.0
blspy==1.0.16
build==0.10.0
CacheControl==0.12.11
cached-property==1.5.2
cachetools==5.3.0
cairo-rs-py==0.1.2
certifi==2023.5.7
cffi==1.15.1
cfgv==3.3.1
chardet==5.0.0
charset-normalizer==3.1.0
chia_rs==0.1.16
chiabip158==1.1
chiapos==1.0.11
chiavdf==1.0.8
chompjs==1.1.9
cleo==2.0.1
click==8.1.3
cloudpickle==2.1.0
clvm==0.9.7
clvm-tools==0.4.6
clvm_tools_rs==0.1.25
codecov-cli==0.1.11
colorama==0.4.5
colorlog==6.7.0
commitizen==2.40.0
commonmark==0.9.1
concurrent-log-handler==0.9.20
construct==2.10.68
construct-classes==0.1.2
contourpy==1.0.6
cookiecutter==2.1.1
cosmospy==6.0.0
coverage==7.2.7
crashtest==0.4.1
crypto-cpp-py==1.2.0
cryptography==41.0.0
cycler==0.11.0
cytoolz==0.12.1
dataclassy==0.11.1
decli==0.5.2
decorator==5.1.1
Deprecated==1.2.14
distlib==0.3.6
dnslib==0.9.23
dnspython==2.2.1
docopt==0.6.2
docutils==0.18.1
dulwich==0.21.3
ecdsa==0.18.0
eip712==0.2.1
eth-abi==4.0.0
eth-account==0.8.0
-e git+ssh://git@github.com/antazoey/ape.git@adb1e04dedbbfad7c4cc8dfc0f80928b723adbed#egg=eth_ape
eth-bloom==2.0.0
eth-event==1.2.3
eth-hash==0.5.1
eth-keyfile==0.6.1
eth-keys==0.4.0
eth-rlp==0.3.0
eth-tester==0.9.0b1
eth-typing==3.3.0
eth-utils==2.1.0
-e git+ssh://git@github.com/unparalleled-js/ethpm-types.git@dffcb6b2fe17f858c95d07499aafe1d66e939dfa#egg=ethpm_types
evm-trace==0.1.0a21
exceptiongroup==1.1.1
execnet==1.9.0
executing==1.2.0
fastapi==0.93.0
fastecdsa==2.3.0
filelock==3.8.0
flake8==6.0.0
flake8-breakpoint==1.1.0
flake8-plugin-utils==1.3.2
flake8-print==4.0.1
Flask==2.0.3
Flask-Cors==3.0.10
fonttools==4.38.0
frozendict==1.2
frozenlist==1.3.3
furo==2022.12.7
gitdb==4.0.9
GitPython==3.1.27
gprof2dot==2022.7.29
greenlet==2.0.2
gunicorn==20.1.0
h11==0.14.0
hdwallets==0.1.2
hexbytes==0.3.0
hidapi==0.13.1
html5lib==1.1
httpcore==0.17.2
httpx==0.24.1
hypothesis==6.27.3
hypothesis-jsonschema==0.19.0
identify==2.5.4
idna==3.4
ijson==3.2.0.post0
imagesize==1.4.1
importlib-metadata==6.6.0
inflection==0.5.0
iniconfig==2.0.0
installer==0.7.0
ipdb==0.13.11
ipfshttpclient==0.8.0a2
ipython==8.12.2
isort==5.12.0
itsdangerous==2.1.2
jaraco.classes==3.2.3
jedi==0.18.2
Jinja2==3.1.2
jinja2-time==0.2.0
jsonschema==4.17.3
keyring==23.13.1
kiwisolver==1.4.4
lark==1.1.5
lark-parser==0.12.0
lazy-object-proxy==1.9.0
lazyasd==0.1.4
libusb1==3.0.0
linkify-it-py==1.0.3
lockfile==0.12.2
lru-dict==1.2.0
markdown-it-py==2.2.0
MarkupSafe==2.1.2
marshmallow==3.17.1
marshmallow-dataclass==8.4.2
marshmallow-enum==1.5.1
marshmallow-oneofschema==3.0.1
matplotlib==3.6.2
matplotlib-inline==0.1.6
mccabe==0.7.0
mdformat==0.7.16
mdformat-gfm==0.3.5
mdformat_footnote==0.1.1
mdformat_frontmatter==0.4.1
mdformat_pyproject==0.0.1
mdformat_tables==0.4.1
mdit-py-plugins==0.3.5
mdurl==0.1.2
mnemonic==0.20
more-itertools==9.1.0
morphys==1.0
mpmath==1.2.1
msgpack==1.0.4
msgspec==0.15.1
multiaddr==0.0.9
multidict==6.0.4
mypy==0.991
mypy-extensions==0.4.4
myst-parser==1.0.0
mythx-models==1.9.1
netaddr==0.8.0
nodeenv==1.7.0
numpy==1.24.3
packaging==23.1
pandas==1.5.3
pandas-stubs==1.2.0.62
parsimonious==0.9.0
parso==0.8.3
pathspec==0.11.1
pbr==5.10.0
pexpect==4.8.0
pickleshare==0.7.5
Pillow==9.3.0
pipdeptree==2.5.0
pkginfo==1.9.6
platformdirs==3.5.1
pluggy==1.0.0
pockets==0.9.1
poetry==1.4.1
poetry-core==1.5.2
poetry-plugin-export==1.3.0
portalocker==2.7.0
pre-commit==2.20.0
prometheus-client==0.17.0
prompt-toolkit==3.0.38
protobuf==4.23.2
psutil==5.9.4
ptyprocess==0.7.0
pure-eval==0.2.2
py==1.11.0
py-cid==0.3.0
py-cui==0.1.6
py-ecc==6.0.0
py-evm==0.7.0a2
py-geth==3.13.0
py-multibase==1.0.3
py-multicodec==0.2.1
py-multihash==0.2.3
py-solc-ast==1.2.9
py-solc-x==1.1.1
pycodestyle==2.10.0
pycoingecko==3.1.0
pycparser==2.21
pycron==3.0.0
pycryptodome==3.18.0
pydantic==2.0.3
pydantic-settings==2.0.2
pydantic_core==2.3.0
pyethash==0.1.27
pyflakes==3.0.1
pygit2==1.11.1
PyGithub==1.58.2
Pygments==2.15.1
pygments-lexer-solidity==0.7.0
PyJWT==2.7.0
pylint==2.12.2
pylint-quotes==0.2.3
PyNaCl==1.5.0
pyparsing==3.0.9
pyproject_hooks==1.0.0
pyrsistent==0.19.3
pysha3==1.0.2
pytest==7.3.1
pytest-asyncio==0.20.3
pytest-cov==4.1.0
pytest-forked==1.6.0
pytest-mock==3.8.2
pytest-profiling==1.7.0
pytest-watch==4.2.0
pytest-xdist==2.5.0
python-baseconv==1.2.2
python-dateutil==2.8.2
python-dotenv==1.0.0
python-slugify==6.1.2
python-vlc==3.0.18121
pythx==1.6.1
pytimeparse==1.1.8
pytz==2023.3
pyupgrade==3.2.3
PyYAML==6.0
questionary==1.10.0
rapidfuzz==2.13.4
readme-renderer==37.3
regex==2023.5.5
requests==2.31.0
requests-toolbelt==0.10.1
rfc3986==2.0.0
rich==12.6.0
rich-click==1.5.2
rlp==3.0.0
ruamel.yaml==0.17.21
ruamel.yaml.clib==0.2.7
safe-pysha3==1.0.4
semantic-version==2.10.0
setproctitle==1.2.3
shellingham==1.5.0
-e git+ssh://git@github.com/antazoey/silverback.git@76c42329113b6ac5484f5a156016390a8f458f3f#egg=silverback
simple-rlp==0.1.3
six==1.16.0
smart-open==6.3.0
smmap==5.0.0
sniffio==1.3.0
snowballstemmer==2.2.0
sortedcontainers==2.4.0
soupsieve==2.3.2.post1
Sphinx==6.1.3
sphinx-basic-ng==1.0.0b1
sphinx-click==4.4.0
sphinx-plausible==0.1.2
sphinx-rtd-theme==1.2.0
sphinxcontrib-applehelp==1.0.2
sphinxcontrib-devhelp==1.0.2
sphinxcontrib-htmlhelp==2.0.0
sphinxcontrib-jquery==4.1
sphinxcontrib-jsmath==1.0.1
sphinxcontrib-napoleon==0.7
sphinxcontrib-qthelp==1.0.3
sphinxcontrib-serializinghtml==1.1.5
SQLAlchemy==2.0.15
stack-data==0.6.2
starlette==0.25.0
stevedore==4.0.0
sympy==1.11.1
taskiq==0.6.0
taskiq-dependencies==1.2.4
termcolor==2.2.0
text-unidecode==1.3
tokenize-rt==5.0.0
tokenlists==0.1.3
toml==0.10.2
tomli==2.0.1
tomlkit==0.11.6
toolz==0.12.0
tqdm==4.65.0
traitlets==5.9.0
tree-sitter==0.20.1
trezor==0.13.6
trie==2.1.0
trove-classifiers==2022.12.1
twine==4.0.2
typeguard==2.13.3
types-pkg-resources==0.1.3
types-PyYAML==6.0.11
types-requests==2.28.11.15
types-setuptools==65.5.0.3
types-SQLAlchemy==1.4.50
types-urllib3==1.26.25.8
typing-inspect==0.8.0
typing_extensions==4.7.1
uc-micro-py==1.0.1
urllib3==2.0.2
varint==1.0.2
virtualenv==20.16.4
vvm==0.1.0
watchdog==3.0.0
wcwidth==0.2.6
web3==6.5.0
webencodings==0.5.1
websockets==11.0.3
Werkzeug==2.0.3
wrapt==1.15.0
xattr==0.10.1
yarl==1.9.2
zipp==3.15.0
zstd==1.5.2.6
pacrob commented 11 months ago

Hey @antazoey , I'm trying to reproduce, but I just get a MemoryError with no further output. Are you able to provide more info?