Skip to content

eql-encryption-tests: heap_hygiene "storage-only value sealed by value" fails at random on Linux CI #1757

Open

Description

@coderdan

Background

packages/eql/tests/encryption/tests/heap_hygiene.rs checks that encrypting and decrypting with the EQL types never frees memory that still contains plaintext. EQL (Encrypt Query Language) is the SQL library CipherStash installs in the customer's database, and eql-bindings contains its Rust types.

The test binary replaces the global memory allocator with a spy. While a test watches its thread, the spy scans every block that thread frees for a marker string, zq-heap-marker-7f3a9c. Every plaintext under test contains that marker. A freed block that contains the marker fails the test.

Problem

owned_seals::a_storage_only_value_sealed_by_value_leaves_no_plaintext_on_the_heap failed once in CI and passed when the same commit ran again.

What we checked:

  • PR feat(stack-encrypt,eql-bindings,golang): open one child of a JSON node, bound to its parent #1751 does not change heap_hygiene.rs, Json, or Ciphertext.
  • The marker is 21 bytes, so ciphertext cannot contain it by chance.
  • The spy scans the whole block, using the allocation's size from its Layout. For a String, that includes the spare capacity past its length.
  • The test builds its JSON document with document() before the watch starts. Building it frees temporary strings that contain the marker, and nothing wipes them, since the watch is not on yet.

What we think happens, not yet confirmed: the allocator reuses one of those unwiped blocks for the ciphertext String. The ciphertext fills only part of the block, so the old marker bytes stay in the spare capacity. When the Json value drops, the spy finds them. The result depends on how the allocator reuses blocks. That would explain why the test fails rarely, and only on Linux so far.

We have not ruled out a real defect. For example, a buffer that held the plaintext JSON text could be wiped only up to its length and then reused for the ciphertext. That would leave plaintext in memory in production too.

Why this matters: a check that fails at random teaches people to rerun it without reading the failure. Then a real leak in the same test would also get a rerun.

Proposal

  1. Find out which it is. Record the address of each block freed unwiped before the watch starts, then check whether the failing block is one of them. Or run the test in a loop on Linux, and have the spy print the marker's offset in the block and the String's length.
  2. If it is stale spare capacity, make the test unable to see bytes from before the watch. For example, have the spy wipe every block it frees while the test is not watching. Or build every marked value inside a wiped scope.
  3. If it is a real defect, fix the code that leaves the plaintext behind, and keep the test as it is.
  4. Either way, add a test that reuses a dirty block on purpose, so the result does not depend on the allocator.

Activity

  1. added
    bug
    Rust
    on Nov 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    RustSDKbug

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions