SecurityInnovation / PGPy

Pretty Good Privacy for Python
BSD 3-Clause "New" or "Revised" License
313 stars 98 forks source link

pgpy.errors.PGPError: bytearray index out of range #459

Open sharmaavi1996 opened 1 year ago

sharmaavi1996 commented 1 year ago

Recently have started seeing this issue come up and was wondering if something has changed to cause this. We have not changed anything on our end. We are attempting to load public keys in .asc format and seeing this error with various different valid gpg public keys:

PGPy version: v0.6.0

line 51, in encrypt_client_secret
    key, _ = pgpy.PGPKey.from_file(recipient_file)
  File "/data/cicd/jenkins/.local/lib/python3.7/site-packages/pgpy/types.py", line 184, in from_file
    po = obj.parse(data)
  File "/data/cicd/jenkins/.local/lib/python3.7/site-packages/pgpy/pgp.py", line 2633, in parse
    for group in iter(group for _, group in itertools.groupby(getpkt, key=pktgrouper()) if not _.endswith('Opaque')):
  File "/data/cicd/jenkins/.local/lib/python3.7/site-packages/pgpy/pgp.py", line 2633, in <genexpr>
    for group in iter(group for _, group in itertools.groupby(getpkt, key=pktgrouper()) if not _.endswith('Opaque')):
  File "/data/cicd/jenkins/.local/lib/python3.7/site-packages/pgpy/pgp.py", line 2617, in _getpkt
    return Packet(d) if d else None
  File "/data/cicd/jenkins/.local/lib/python3.7/site-packages/pgpy/types.py", line 542, in __call__
    raise PGPError(str(ex)) from ex

      File "/data/cicd/jenkins/.local/lib/python3.7/site-packages/pgpy/types.py", line 539, in __call__
    obj.parse(packet)
  File "/data/cicd/jenkins/.local/lib/python3.7/site-packages/pgpy/packet/types.py", line 207, in parse
    super(Opaque, self).parse(packet)
  File "/data/cicd/jenkins/.local/lib/python3.7/site-packages/pgpy/packet/types.py", line 169, in parse
    self.header.parse(packet)
  File "/data/cicd/jenkins/.local/lib/python3.7/site-packages/pgpy/packet/types.py", line 102, in parse
    self._lenfmt = ((packet[0] & 0x40) >> 6)
IndexError: bytearray index out of range