Skip to content

OpenPGP: Mitigate some RuntimeExceptions uncovered using Fuzzing #2123

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 31 commits into
base: main
Choose a base branch
from

Conversation

vanitasvitae
Copy link
Contributor

Hey!

I did run junit-jazzer agains some PGPainless functions and uncovered some bugs in the bcpg codebase.

The commits in this PR harmonize the way malformed or strange packets are handled, by preventing runtime exceptions, such as IndexOutOfBounds, NegativeArraySize, IllegalArgumentExceptions and OutOfMemory errors.

I'm only just getting started with fuzzing, but I can highly recommend it!

This is a dedicated exception type that is thrown for malformed OpenPGP packets
…edPacketException for malformed packets with unexpected kdf parameter length
…ng subpacket parsing as MalformedPacketException
…rmed fingerprint lengths as MalformedPacketException
…known AEAD algorithm as MalformedPacketException
…nction in ECDHPublicBCPGKey) as MalformedPacketException
@ligefeiBouncycastle ligefeiBouncycastle self-requested a review July 13, 2025 23:59
@ligefeiBouncycastle
Copy link
Collaborator

Hi @vanitasvitae,
Thanks for your valuable PR in hardening the PGP packet handling against malformed inputs. Your fuzzing work is much appreciated.

Regarding the UserAttributeSubpacketInputStream.MAX_LEN setting (currently 5MB):

  • We should revisit this limit – a prior fix in the C# library (PR #638) encountered a similar issue where packet lengths could theoretically reach 4,082,119,084 bytes (~3.8GB). The resolution there set the max to 2³⁰ bytes (1,073,741,824 bytes)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants