sciunto-org / python-bibtexparser

Bibtex parser for Python 3
https://bibtexparser.readthedocs.io
MIT License
474 stars 132 forks source link

Crash bug #376

Closed bajinsheng closed 1 year ago

bajinsheng commented 1 year ago

For a file test.bib with the content:

@inproceedings{DBLP:conf/amw/GuagliardoL18,
  author       = {Paolo Guagliardo and
                  Leonid Libkin},
  editor       = {Dan Olteanu and
                  Barbara Poblete},
  title        = {How Standard is the {SQL} Standard?},
  booktitle    = {Proceedings of the 12th Alberto Mendelzon International Workshop on
                  Foundations of Data Management, Cali, Colombia, May 21-25, 2018},
  series       = {{CEUR} Workshop Proceedings},
  volume       = {2100},
  publisher    = {CEUR-WS.org},
  year         = {2018},
  url          = {https://ceur-ws.org/Vol-2100/paper16.pdf},
  timestamp    = {Fri, 10 Mar 2023 16:23:19 +0100},
  biburl       = {https://dblp.org/rec/conf/amw/GuagliardoL18.bib},
  bibsource    = {dblp computer science bibliography, https://dblp.org}
}

The write_string function call will crash:

bib = bibtexparser.parse_file("test.bib")
bibtexparser.write_string(bib)
  File "/home/user/test/bug.py", line 6, in <module>
    bibtexparser.write_string(bib)
  File "/home/user/.local/lib/python3.10/site-packages/bibtexparser/entrypoint.py", line 168, in write_string
    return write_string(library, bibtex_format=bibtex_format)
  File "/home/user/.local/lib/python3.10/site-packages/bibtexparser/entrypoint.py", line 168, in write_string
    return write_string(library, bibtex_format=bibtex_format)
  File "/home/user/.local/lib/python3.10/site-packages/bibtexparser/entrypoint.py", line 168, in write_string
    return write_string(library, bibtex_format=bibtex_format)
  [Previous line repeated 969 more times]
  File "/home/user/.local/lib/python3.10/site-packages/bibtexparser/entrypoint.py", line 166, in write_string
    library = middleware.transform(library=library)
  File "/home/user/.local/lib/python3.10/site-packages/bibtexparser/middlewares/middleware.py", line 77, in transform
    blocks = [self.transform_block(b, library) for b in library.blocks]
  File "/home/user/.local/lib/python3.10/site-packages/bibtexparser/middlewares/middleware.py", line 77, in <listcomp>
    blocks = [self.transform_block(b, library) for b in library.blocks]
  File "/home/user/.local/lib/python3.10/site-packages/bibtexparser/middlewares/middleware.py", line 100, in transform_block
    block = block if self.allow_inplace_modification else deepcopy(block)
  File "/usr/lib/python3.10/copy.py", line 172, in deepcopy
    y = _reconstruct(x, memo, *rv)
  File "/usr/lib/python3.10/copy.py", line 271, in _reconstruct
    state = deepcopy(state, memo)
  File "/usr/lib/python3.10/copy.py", line 146, in deepcopy
    y = copier(x, memo)
  File "/usr/lib/python3.10/copy.py", line 231, in _deepcopy_dict
    y[deepcopy(key, memo)] = deepcopy(value, memo)
  File "/usr/lib/python3.10/copy.py", line 146, in deepcopy
    y = copier(x, memo)
  File "/usr/lib/python3.10/copy.py", line 206, in _deepcopy_list
    append(deepcopy(a, memo))
  File "/usr/lib/python3.10/copy.py", line 172, in deepcopy
    y = _reconstruct(x, memo, *rv)
  File "/usr/lib/python3.10/copy.py", line 271, in _reconstruct
    state = deepcopy(state, memo)
  File "/usr/lib/python3.10/copy.py", line 146, in deepcopy
    y = copier(x, memo)
  File "/usr/lib/python3.10/copy.py", line 231, in _deepcopy_dict
    y[deepcopy(key, memo)] = deepcopy(value, memo)
  File "/usr/lib/python3.10/copy.py", line 146, in deepcopy
    y = copier(x, memo)
  File "/usr/lib/python3.10/copy.py", line 182, in _deepcopy_atomic
    def _deepcopy_atomic(x, memo):
  File "_pydevd_bundle/pydevd_cython.pyx", line 1457, in _pydevd_bundle.pydevd_cython.SafeCallWrapper.__call__
RecursionError: maximum recursion depth exceeded while calling a Python object
MiWeiss commented 1 year ago

Thanks for reporting. This is odd. Is this going to be closed by #377?

bajinsheng commented 1 year ago

Yup. The PR aims to fix this issue.