kimbauters / ZIMply

An easy to use offline reader for ZIM files right in your browser!
Other
80 stars 16 forks source link

`struct.error: unpack requires a buffer of 2 bytes` thrown when accessing some files #31

Open abdnh opened 2 years ago

abdnh commented 2 years ago

I had this error thrown for seemingly random URLs when trying different ZIM files. To reproduce with one sample file:

  1. Download the wikipedia_ar_computer_maxi.zim file from the Kiwix collection (direct link: https://download.kiwix.org/zim/wikipedia_ar_computer_maxi.zim)
  2. Serve the file using ZIMply then navigate to the /w/index.php page.
  3. An error like this is thrown:
    
    2022-09-26 01:08:07 [FALCON] [ERROR] GET /w/index.php => Traceback (most recent call last):
    File "falcon\app.py", line 365, in falcon.app.App.__call__
    File "D:\dev\zimply-demo\venv\lib\site-packages\zimply\zimply.py", line 717, in on_get
    article = ZIMRequestHandler.zim.get_article_by_url(namespace, url)
    File "D:\dev\zimply-demo\venv\lib\site-packages\zimply\zimply.py", line 537, in get_article_by_url
    entry, idx = self._get_entry_by_url(namespace, url)  # get the entry
    File "D:\dev\zimply-demo\venv\lib\site-packages\zimply\zimply.py", line 516, in _get_entry_by_url
    entry = self.read_directory_entry_by_index(middle)
    File "D:\dev\zimply-demo\venv\lib\site-packages\zimply\zimply.py", line 454, in read_directory_entry_by_index
    directory_values = self._read_directory_entry(offset)
    File "D:\dev\zimply-demo\venv\lib\site-packages\zimply\zimply.py", line 435, in _read_directory_entry        
    fields = unpack("<H", self.file.read(2))
    struct.error: unpack requires a buffer of 2 bytes