Breaking Guava’s BloomFilter: A 6-Byte Denial of Service
Guava's BloomFilter.readFrom() reads a dataLength field from the input stream and uses it to size an array without any upper bound. An attacker controlling the serialized input could supply a tiny stream that claims a huge length, forcing a multi-gigabyte allocation and an OutOfMemoryError that may crash the process.
Security
The full write-up lives on its author's site
It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.
Context
Guava's BloomFilter is a probabilistic set-membership structure. Applications use it to avoid unnecessary cache lookups or to filter out obviously-absent keys before running a more expensive check. Guava lets you serialise a BloomFilter to a stream and reconstruct it later through BloomFilter.readFrom(InputStream, Funnel).
The serialised format is simple:
byte strategyOrdinal
byte numHashFunctions
int dataLength
long[dataLength] data
The third field is where the trouble lives. readFrom() reads dataLength straight from the stream and uses it to size an internal long[] array. It checks no upper bound and never confirms how much data the stream actually holds.
Setup
The work targeted Guava's BloomFilter.readFrom() directly. The tooling was a Jazzer-based harness named BloomFilterReadFromFuzzer.java, written for inclusion in OSS-Fuzz, Google's continuous fuzzing infrastructure for open-source projects. The finding was reported through Google's OSS VRP program.
Finding it
The serialised format above is the whole attack surface. readFrom() reads dataLength from the stream and passes it into allocation logic without validating that the claimed size is plausible given the remaining stream contents, and without bounding the value against any sane maximum.
Rather than hand-crafting a single proof-of-concept input, the researcher wrote a fuzz harness that targets BloomFilter.readFrom() and lets the fuzzer search for the input. Within seconds of running, the fuzzer found that the minimum 6-byte input reliably triggered multi-gigabyte allocation attempts, with an amplification factor in the billions.
Exploitation
Step 1: Understand what readFrom() does with the stream
When readFrom() processes a malicious stream:
- It reads
strategyOrdinalandnumHashFunctions, one byte each. - It reads
dataLengthas a 4-byte big-endian integer. - It allocates a
long[dataLength]array before checking whether the stream contains that many longs.
Each long takes 8 bytes, so an attacker can set dataLength to something like 0x7FFFFFFF and force Guava to attempt roughly 16 GB of allocation, from an input that might itself be a handful of bytes. The allocation happens deep inside LockFreeBitArray's construction path, well before any check against the remaining stream length.
The result is deterministic: the JVM throws OutOfMemoryError.
Step 2: Build the harness skeleton
The harness works in three stages. First, it rejects anything under 6 bytes immediately, since that is the minimum needed to even reach the vulnerable allocation: 1 byte for strategyOrdinal, 1 for numHashFunctions, 4 for dataLength.
Step 3: Parse dataLength for reporting before Guava runs
The harness then parses dataLength itself out of bytes 2 through 5, big-endian, purely for reporting. This step never touches Guava. The goal is for the crash report to already contain the requested allocation size and an amplification factor (requested bytes divided by input size) before Guava even runs, so both are computed up front with Math.multiplyExact, wrapped in a try/catch so an overflow in the harness's own arithmetic does not mask the real bug.
Step 4: Invoke Guava and force lazy allocation
The raw bytes are handed to BloomFilter.readFrom() inside a try-with-resources block, and then mightContain("probe") is called on the result. That extra call matters: it forces any lazily-triggered allocation to run before the harness exits, so a crash that only happens on first use of the deserialised filter is not missed.
Step 5: Triage the outcome
The catch logic does the actual triage. An OutOfMemoryError is caught specifically and turned into a FuzzerSecurityIssueCritical, with a message built from the input size, the parsed dataLength, the requested allocation in bytes, and the amplification factor:
message.append("Amplification factor: ")
.append(String.format("%.2f", amplification))
.append("x\n");
That message also states the root cause directly in the crash report, so anyone triaging the OSS-Fuzz finding does not have to reverse-engineer it from a bare stack trace. Meanwhile IOException, IllegalArgumentException, and ArithmeticException all pass through silently in a separate catch block. Those three represent Guava (or the harness's own overflow check) correctly rejecting malformed input, and flagging them as issues would just add noise.
Step 6: Observe the result
Within seconds of running, the fuzzer found the minimum 6-byte input reliably triggered multi-gigabyte allocation attempts. The amplification factor ran into the billions.
Root cause
BloomFilter.readFrom() trusts the dataLength metadata embedded in the input and passes it straight into allocation logic. It never validates that the claimed size is plausible given the remaining stream contents, and it never bounds the value against any sane maximum. The allocation happens before any check against the remaining stream length, so the stream contents cannot act as a defence.
This is CWE-770, allocation of resources without limits or throttling. The report frames it as a reminder that deserialisation code deserves the same scrutiny as any other untrusted-input boundary, even in something as mundane as a probabilistic data structure.
Impact
The JVM throws OutOfMemoryError. Depending on how the calling application handles deserialisation, that error can crash a worker thread, kill a process, or take down any service that deserialises Bloom filters from untrusted sources: cache warmers, RPC payloads, uploaded snapshots, and similar paths. The input needed is as little as 6 bytes, and the outcome is deterministic rather than probabilistic.
Fix
The finding and the fuzz harness were reported through Google's OSS VRP program. Google merged the fuzz target, BloomFilterReadFromFuzzer.java, into OSS-Fuzz's Guava project, so it now runs continuously against Guava's codebase to catch regressions of this exact bug class going forward.
The Guava team then merged a fix that adds a new overload, BloomFilter.readFrom(InputStream, Funnel, long), which lets callers pass a maximum data size to enforce during deserialisation. Both changes reference each other directly: the fix cites the fuzz target, and the fuzz target now guards against regressions of the issue the fix addresses.
Variants to test
- Other length-prefixed deserialisers in utility libraries. Look for any
readFrom-style method that reads a length field and sizes an array from it. A positive result is an allocation attempt whose size is driven by the input rather than by the bytes actually present, visible as anOutOfMemoryErroror a very large allocation in a profiler. - Lazy allocation paths. After deserialisation, call a method that touches the structure (the equivalent of
mightContain("probe")). A positive result is a crash that only appears on first use, which a harness that stops afterreadFrom()would miss. - Minimum-length inputs. Compute the smallest input that reaches the vulnerable allocation (here 1 + 1 + 4 bytes) and try it first. A positive result is a crash from that minimum, which gives the strongest amplification figure for the report.
- Silent exception classes. Decide explicitly which exceptions mean "correctly rejected" and let them pass, so the fuzzer's signal is not drowned. A positive result is a crash report that names the root cause and the requested allocation size without manual triage.
- Overflow in your own arithmetic. Wrap size and amplification calculations in checked arithmetic and a try/catch. A positive result is that an overflow in the harness does not mask the underlying bug.
What happened, in plain words
A library called Guava, made by Google and used inside many Java programs, contains a small helper called BloomFilter. A Bloom filter is a clever way of answering the question "have I seen this item before?" without storing every item. It is used to skip work: if the filter says an item is definitely not present, the program does not need to go and look for it in a slow place such as a database or a cache.
Guava lets a program save a Bloom filter to a file or a network stream and load it back later. The loading function is called BloomFilter.readFrom(). The saved format begins with a few numbers that describe the data that follows, including a number called dataLength that says how much data there is. The loading code reads that number and uses it to decide how much memory to reserve, without ever checking whether the number is reasonable or whether the stream really contains that much data.
That is the whole bug. If an attacker can send a Bloom filter to a program that loads it, the attacker can put a huge number in the dataLength field. The program then tries to reserve an enormous amount of memory, far more than the machine has, and the Java runtime gives up with an error called OutOfMemoryError. The attacker needs only 6 bytes to do this. The result is not random: it happens every time.
This kind of flaw has a name, CWE-770, which means "allocation of resources without limits or throttling". In everyday terms: a hotel clerk who hands out a room key to anyone who writes a number on a form, without checking whether that room exists or whether the guest is real.
The researcher did not just write one malicious file by hand. Instead they built a small program, called a fuzz harness, that throws many different inputs at BloomFilter.readFrom() automatically and watches for crashes. They contributed it to OSS-Fuzz, Google's service that continuously tests open-source projects. Within seconds of running, the fuzzer found the minimum 6-byte input that triggered the problem. The researcher reported it through Google's OSS VRP, a programme that rewards people who find and report security bugs in open-source software. Google added the harness to OSS-Fuzz, and the Guava team later shipped a fix that lets callers set a maximum size for the data being loaded.
Background: what a Bloom filter is and why loading one exists
A Bloom filter is a data structure, meaning a way of organising information in memory. It answers one question: "is this item possibly in the set, or definitely not in it?" It never says "definitely yes". It can occasionally say "possibly yes" for an item that was never added, which is called a false positive. In exchange, it uses very little memory compared with storing the items themselves.
Programs use this to avoid expensive work. Before asking a slow cache or a database whether a key exists, the program asks the Bloom filter. If the filter says "definitely not", the program skips the slow lookup entirely. This saves time on every request for a key that is not there.
Guava lets a program write a Bloom filter to a stream and read it back later with BloomFilter.readFrom(InputStream, Funnel). A stream here is just a sequence of bytes coming from somewhere: a file, a network connection, an uploaded snapshot. The Funnel is a small helper object that tells Guava how to turn items into bytes when the filter is built; for loading, it is passed along so the reconstructed filter behaves the same way.
The saved format is simple, and it is worth reading slowly because every part of the bug lives in it:
byte strategyOrdinal
byte numHashFunctions
int dataLength
long[dataLength] data
Line by line:
byte strategyOrdinal: one byte that says which internal strategy the filter uses. A byte is the smallest unit of data a computer usually handles, holding a value from 0 to 255.byte numHashFunctions: one byte saying how many hash functions the filter uses. A hash function is a recipe that turns an item into a number; Bloom filters use several of them to decide which bits to set.int dataLength: a four-byte whole number saying how manylongvalues of data follow. Anintin Java is a 32-bit signed integer, so it can hold values up to about 2.1 billion.long[dataLength] data: the actual data, as an array oflongvalues. Alongin Java is 8 bytes, so this line describesdataLengthtimes 8 bytes of data.
The third field is where the trouble lives. readFrom() reads dataLength straight from the stream and uses it to size an internal long[] array. It checks no upper bound and never confirms how much data the stream actually holds.
Setup: what was tested and with which tools
The work targeted Guava's BloomFilter.readFrom() directly. The tooling was a Jazzer-based harness named BloomFilterReadFromFuzzer.java, written for inclusion in OSS-Fuzz, Google's continuous fuzzing infrastructure for open-source projects. Jazzer is a fuzzer for Java: a tool that generates many inputs automatically and runs the target code on each one, looking for crashes.
The finding was reported through Google's OSS VRP program. OSS VRP stands for Open Source Software Vulnerability Reward Program: a scheme where people who find security problems in open-source projects can report them and, if the report is valid, receive a reward.
Finding it: why a fuzzer instead of a hand-made file
The serialised format above is the whole attack surface. In security, the attack surface is every place where outside data can enter a program. Here it is one function reading one stream.
readFrom() reads dataLength from the stream and passes it into allocation logic without validating that the claimed size is plausible given the remaining stream contents, and without bounding the value against any sane maximum. Allocation means reserving memory for the array.
Rather than hand-crafting a single proof-of-concept input, the researcher wrote a fuzz harness that targets BloomFilter.readFrom() and lets the fuzzer search for the input. A proof-of-concept input is one specific malicious file that demonstrates the bug. Writing one by hand works, but it only proves that one input. A fuzzer tries many variations and can find the smallest input that triggers the problem, and it keeps working as a regression test afterwards.
Within seconds of running, the fuzzer found that the minimum 6-byte input reliably triggered multi-gigabyte allocation attempts, with an amplification factor in the billions. Amplification factor here means the number of bytes the program tries to reserve divided by the number of bytes the attacker sent. A factor in the billions means a handful of bytes causes gigabytes of memory to be requested.
Exploitation: how the bug actually plays out
Step 1: Understand what readFrom() does with the stream
When readFrom() processes a malicious stream:
- It reads
strategyOrdinalandnumHashFunctions, one byte each. - It reads
dataLengthas a 4-byte big-endian integer. - It allocates a
long[dataLength]array before checking whether the stream contains that many longs.
Big-endian means the most significant byte comes first, the way we write numbers: the digit that matters most is on the left. So four bytes 00 00 00 06 mean the number 6.
Each long takes 8 bytes, so an attacker can set dataLength to something like 0x7FFFFFFF and force Guava to attempt roughly 16 GB of allocation, from an input that might itself be a handful of bytes. 0x7FFFFFFF is a number written in hexadecimal, a base-16 notation often used for raw bytes. It equals 2,147,483,647, the largest value a signed 32-bit integer can hold. Multiply that by 8 bytes per long and you get roughly 16 GB.
The allocation happens deep inside LockFreeBitArray's construction path, well before any check against the remaining stream length. LockFreeBitArray is the internal class that actually holds the bits of the filter; the array of long values is its storage. Because the memory is reserved before anyone looks at how much data is really there, the stream contents cannot act as a defence.
The result is deterministic: the JVM throws OutOfMemoryError. The JVM is the Java Virtual Machine, the program that runs Java code. OutOfMemoryError is the error it raises when it cannot get the memory a program asks for.
Step 2: Build the harness skeleton
The harness works in three stages. First, it rejects anything under 6 bytes immediately, since that is the minimum needed to even reach the vulnerable allocation: 1 byte for strategyOrdinal, 1 for numHashFunctions, 4 for dataLength.
Why bother with this check? Because a fuzzer will send all sorts of tiny inputs, and those cannot reach the dangerous line. Filtering them out early keeps the harness focused and avoids wasting time on inputs that can never trigger the bug.
Step 3: Parse dataLength for reporting before Guava runs
The harness then parses dataLength itself out of bytes 2 through 5, big-endian, purely for reporting. This step never touches Guava. The goal is for the crash report to already contain the requested allocation size and an amplification factor (requested bytes divided by input size) before Guava even runs, so both are computed up front with Math.multiplyExact, wrapped in a try/catch so an overflow in the harness's own arithmetic does not mask the real bug.
A few terms here. Parsing means reading raw bytes and turning them into a number the program can use. Math.multiplyExact is a Java method that multiplies two numbers and throws an exception if the result does not fit in the type, instead of silently wrapping around to a wrong value. A try/catch block is Java's way of saying "try this code, and if it throws an error, run this other code instead". Overflow means a number grew too large for its container and wrapped around, like an old car odometer rolling over from 99999 to 00000.
Why compute the numbers yourself before calling Guava? Because if Guava crashes, the crash report should already say how big the requested allocation was and how much it was amplified. Otherwise whoever reads the report has to work it out by hand from a stack trace, which is the list of function calls that led to the crash.
Step 4: Invoke Guava and force lazy allocation
The raw bytes are handed to BloomFilter.readFrom() inside a try-with-resources block, and then mightContain("probe") is called on the result. That extra call matters: it forces any lazily-triggered allocation to run before the harness exits, so a crash that only happens on first use of the deserialised filter is not missed.
A try-with-resources block is Java syntax that automatically closes a stream when the block finishes, even if an error occurs. mightContain("probe") is the Bloom filter's normal query method: it asks whether the string probe might be in the set. Calling it after loading forces the filter to actually be used, which is when some allocations might happen. Lazy allocation means memory is reserved only when it is first needed, not when the object is created. If the harness stopped right after readFrom(), it could miss a crash that only appears on first use.
Step 5: Triage the outcome
The catch logic does the actual triage. Triage here means sorting outcomes into "this is a real security problem" and "this is normal rejection of bad input". An OutOfMemoryError is caught specifically and turned into a FuzzerSecurityIssueCritical, with a message built from the input size, the parsed dataLength, the requested allocation in bytes, and the amplification factor:
message.append("Amplification factor: ")
.append(String.format("%.2f", amplification))
.append("x\n");
Line by line:
message.append("Amplification factor: ")adds the literal textAmplification factor:to the end of a text buffer calledmessage..append(String.format("%.2f", amplification))formats the numberamplificationwith two decimal places and adds it.%.2fmeans "a floating-point number with two digits after the decimal point"..append("x\n")adds anxand a newline, so the line reads something likeAmplification factor: 1234567890.00x.
That message also states the root cause directly in the crash report, so anyone triaging the OSS-Fuzz finding does not have to reverse-engineer it from a bare stack trace. Meanwhile IOException, IllegalArgumentException, and ArithmeticException all pass through silently in a separate catch block. Those three represent Guava (or the harness's own overflow check) correctly rejecting malformed input, and flagging them as issues would just add noise.
IOException means an input/output problem, such as the stream ending early. IllegalArgumentException means a method was given an argument it cannot accept. ArithmeticException is what Math.multiplyExact throws on overflow. All three are the program saying "this input is bad, I refuse it", which is exactly what should happen. Treating those as security findings would drown the real signal in false alarms.
Step 6: Observe the result
Within seconds of running, the fuzzer found the minimum 6-byte input reliably triggered multi-gigabyte allocation attempts. The amplification factor ran into the billions.
Root cause
BloomFilter.readFrom() trusts the dataLength metadata embedded in the input and passes it straight into allocation logic. It never validates that the claimed size is plausible given the remaining stream contents, and it never bounds the value against any sane maximum. The allocation happens before any check against the remaining stream length, so the stream contents cannot act as a defence.
This is CWE-770, allocation of resources without limits or throttling. CWE stands for Common Weakness Enumeration, a public catalogue of known kinds of software weakness, each with a number. The report frames it as a reminder that deserialisation code deserves the same scrutiny as any other untrusted-input boundary, even in something as mundane as a probabilistic data structure. Deserialisation means turning a stream of bytes back into a live object in memory. An untrusted-input boundary is any point where data from outside the program enters it.
Impact
The JVM throws OutOfMemoryError. Depending on how the calling application handles deserialisation, that error can crash a worker thread, kill a process, or take down any service that deserialises Bloom filters from untrusted sources: cache warmers, RPC payloads, uploaded snapshots, and similar paths. The input needed is as little as 6 bytes, and the outcome is deterministic rather than probabilistic.
A worker thread is one of the parallel streams of work inside a server. An RPC payload is the body of a remote procedure call, a way for one program to ask another to run a function. A cache warmer is a job that pre-loads data into a cache at startup. An uploaded snapshot is a saved copy of some data that a user sends to the service. In all these cases, if the bytes come from outside, an attacker can craft them.
Fix
The finding and the fuzz harness were reported through Google's OSS VRP program. Google merged the fuzz target, BloomFilterReadFromFuzzer.java, into OSS-Fuzz's Guava project, so it now runs continuously against Guava's codebase to catch regressions of this exact bug class going forward. A regression is when a bug that was fixed comes back because of a later change.
The Guava team then merged a fix that adds a new overload, BloomFilter.readFrom(InputStream, Funnel, long), which lets callers pass a maximum data size to enforce during deserialisation. An overload is a second version of a method with extra parameters. Here the extra long parameter is the maximum size the caller is willing to accept, so the loading code can refuse anything larger.
Both changes reference each other directly: the fix cites the fuzz target, and the fuzz target now guards against regressions of the issue the fix addresses.
Variants to test
- Other length-prefixed deserialisers in utility libraries. Look for any
readFrom-style method that reads a length field and sizes an array from it. A positive result is an allocation attempt whose size is driven by the input rather than by the bytes actually present, visible as anOutOfMemoryErroror a very large allocation in a profiler. A profiler is a tool that watches a running program's memory and CPU use. - Lazy allocation paths. After deserialisation, call a method that touches the structure (the equivalent of
mightContain("probe")). A positive result is a crash that only appears on first use, which a harness that stops afterreadFrom()would miss. - Minimum-length inputs. Compute the smallest input that reaches the vulnerable allocation (here 1 + 1 + 4 bytes) and try it first. A positive result is a crash from that minimum, which gives the strongest amplification figure for the report.
- Silent exception classes. Decide explicitly which exceptions mean "correctly rejected" and let them pass, so the fuzzer's signal is not drowned. A positive result is a crash report that names the root cause and the requested allocation size without manual triage.
- Overflow in your own arithmetic. Wrap size and amplification calculations in checked arithmetic and a try/catch. A positive result is that an overflow in the harness does not mask the underlying bug.
Glossary
- Allocation: reserving a block of memory for a program to use.
- Amplification factor: the number of bytes a program tries to reserve divided by the number of bytes the attacker sent.
- Attack surface: every place where outside data can enter a program.
- Big-endian: a way of storing numbers where the most significant byte comes first.
- Bloom filter: a data structure that answers "possibly present or definitely absent" using little memory, with occasional false positives.
- Byte: the smallest usual unit of data, holding a value from 0 to 255.
- Cache: a fast storage layer that holds data so it does not have to be fetched from a slower place.
- Cache warmer: a job that pre-loads data into a cache at startup.
- CWE: Common Weakness Enumeration, a public catalogue of software weakness types, each with a number.
- CWE-770: allocation of resources without limits or throttling.
- Data structure: a way of organising information in memory.
- Deserialisation: turning a stream of bytes back into a live object in memory.
- Deterministic: happening the same way every time, not by chance.
- Exception: an error signal a program raises when something goes wrong.
- False positive: a Bloom filter saying an item might be present when it was never added.
- Fuzz harness: a small program that feeds many generated inputs to a target and watches for crashes.
- Fuzzer: a tool that generates many inputs automatically to find crashes.
- Hash function: a recipe that turns an item into a number.
- Hexadecimal: a base-16 way of writing numbers, often used for raw bytes.
IOException: an error meaning an input/output problem, such as a stream ending early.IllegalArgumentException: an error meaning a method was given an argument it cannot accept.ArithmeticException: an error raised when arithmetic cannot be done, such as an overflow in checked arithmetic.int: a 32-bit signed whole number in Java, holding values up to about 2.1 billion.- Jazzer: a fuzzer for Java programs.
- JVM: Java Virtual Machine, the program that runs Java code.
- Lazy allocation: reserving memory only when it is first needed, not when an object is created.
long: an 8-byte whole number in Java.Math.multiplyExact: a Java method that multiplies numbers and throws an exception on overflow instead of wrapping around.- OSS-Fuzz: Google's continuous fuzzing service for open-source projects.
- OSS VRP: Open Source Software Vulnerability Reward Program, a scheme for reporting security bugs in open-source software.
- Overflow: a number growing too large for its container and wrapping around.
- Overload: a second version of a method with extra parameters.
- Parsing: reading raw bytes and turning them into a value the program can use.
- Proof-of-concept input: one specific malicious input that demonstrates a bug.
- Profiler: a tool that watches a running program's memory and CPU use.
- Regression: a bug that was fixed coming back because of a later change.
- RPC payload: the body of a remote procedure call, a way for one program to ask another to run a function.
- Stack trace: the list of function calls that led to a crash.
- Stream: a sequence of bytes coming from a file, a network connection or similar source.
- Triage: sorting outcomes into real security problems and normal rejections of bad input.
- Try/catch: Java syntax for trying code and handling errors it may raise.
- Try-with-resources: Java syntax that automatically closes a resource such as a stream when a block finishes.
- Untrusted-input boundary: any point where data from outside a program enters it.
- Worker thread: one of the parallel streams of work inside a server.