git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH v2 00/12] reftable: harden against corrupted tables

From
Patrick Steinhardt <ps@pks.im>
Date
Jun 29, 2026, 09:02 UTC
Message-ID
<20260629-pks-reftable-hardening-v2-0-b0228e7d908d@pks.im>
In-Reply-To
<20260624-pks-reftable-hardening-v1-0-66e4ce87c6b9@pks.im>
Hi,

this patch series addresses a bunch of errors that may happen when trying to read corrupted tables. These errors include out-of-bounds writes, out-of-bounds reads and the ability to hit abort(3p) calls.

The out-of-bounds write was originally reported by awo on the security mailing list. As we never transfer reftables over the protocol it would require local disk access to create such corrupted reftables, so there isn't really an easy way to exploit these.

In any case, I took that chance and wrote a fuzzer for parsing the tables, which surfaced a bunch of issues. At the end of this series though the fuzzer can now run for an extended amount of time (2hrs+) without surfacing any new issues.

Changes in v2:
  - Introduce a test helper that writes a reftable block.
  - Link to v1: https://patch.msgid.link/20260624-pks-reftable-hardening-v1-0-66e4ce87c6b9@pks.im
Thanks!
Patrick
---
Patrick Steinhardt (12):
      meson: support building fuzzers with libFuzzer
      oss-fuzz: add fuzzer for parsing reftables
      reftable/basics: fix OOB read on binary search of empty range
      reftable/record: don't abort when decoding invalid ref value type
      t/unit-tests: introduce test helper to write reftable blocks
      reftable/block: fix OOB write with bogus inflated log size
      reftable/block: fix OOB read with bogus block size
      reftable/block: fix OOB read with bogus restart count
      reftable/block: fix use of uninitialized memory when binsearch fails
      reftable/block: fix OOB read with bogus restart offset
      reftable/table: fix NULL pointer access when seeking to bogus offsets
      reftable/table: fix OOB read on truncated table
 Makefile                            |   1 +
 ci/run-build-and-minimal-fuzzers.sh |   1 +
 meson.build                         |  15 +++
 meson_options.txt                   |   2 +
 oss-fuzz/.gitignore                 |   1 +
 oss-fuzz/fuzz-reftable.c            |  74 +++++++++++++++
 oss-fuzz/meson.build                |   2 +
 reftable/basics.c                   |   3 +
 reftable/block.c                    |  39 +++++++-
 reftable/record.c                   |   6 +-
 reftable/table.c                    |   7 ++
 t/unit-tests/u-reftable-basics.c    |  11 +++
 t/unit-tests/u-reftable-block.c     | 184 ++++++++++++++++++++++++++++++++----
 t/unit-tests/u-reftable-record.c    |  24 +++++
 t/unit-tests/u-reftable-table.c     |  91 ++++++++++++++++++
 15 files changed, 435 insertions(+), 26 deletions(-)
Range-diff versus v1:
 1:  82275a5448 =  1:  5bb58da117 meson: support building fuzzers with libFuzzer
 2:  8b234b5dc6 =  2:  8d11b15082 oss-fuzz: add fuzzer for parsing reftables
 3:  f265bcf6f4 =  3:  21186da3f1 reftable/basics: fix OOB read on binary search of empty range
 4:  a56c6cb50c =  4:  3c327bacc2 reftable/record: don't abort when decoding invalid ref value type
 -:  ---------- >  5:  4125c76a97 t/unit-tests: introduce test helper to write reftable blocks
 5:  9074372e30 !  6:  e923c23518 reftable/block: fix OOB write with bogus inflated log size
    @@ reftable/block.c: int reftable_block_init(struct reftable_block *block,
     
      ## t/unit-tests/u-reftable-block.c ##
     @@ t/unit-tests/u-reftable-block.c: void test_reftable_block__iterator(void)
    - 	block_writer_release(&writer);
    + 	reftable_block_release(&block);
      	reftable_buf_release(&data);
      }
     +
     +void test_reftable_block__corrupt_log_block_size(void)
     +{
     +	struct reftable_block_source source = { 0 };
    -+	struct block_writer writer = {
    -+		.last_key = REFTABLE_BUF_INIT,
    -+	};
     +	struct reftable_record rec = {
     +		.type = REFTABLE_BLOCK_TYPE_LOG,
     +		.u.log = {
    @@ t/unit-tests/u-reftable-block.c: void test_reftable_block__iterator(void)
     +		},
     +	};
     +	struct reftable_block block = { 0 };
    -+	struct reftable_buf data;
    -+
    -+	data.len = 1024;
    -+	REFTABLE_CALLOC_ARRAY(data.buf, data.len);
    -+	cl_assert(data.buf != NULL);
    ++	struct reftable_buf data = REFTABLE_BUF_INIT;
     +
    -+	cl_must_pass(block_writer_init(&writer, REFTABLE_BLOCK_TYPE_LOG,
    -+				       (uint8_t *) data.buf, data.len,
    -+				       0, hash_size(REFTABLE_HASH_SHA1)));
    -+	cl_must_pass(block_writer_add(&writer, &rec));
    -+	cl_assert(block_writer_finish(&writer) > 0);
    ++	cl_reftable_write_block(&data, REFTABLE_BLOCK_TYPE_LOG, &rec, 1);
     +
     +	/*
     +	 * Log blocks store their inflated size as a big-endian 24-bit integer
    @@ t/unit-tests/u-reftable-block.c: void test_reftable_block__iterator(void)
     +			  REFTABLE_FORMAT_ERROR);
     +
     +	reftable_block_release(&block);
    -+	block_writer_release(&writer);
     +	reftable_buf_release(&data);
     +}
 6:  6877f58485 !  7:  16c2904a96 reftable/block: fix OOB read with bogus block size
    @@ reftable/block.c: int reftable_block_init(struct reftable_block *block,
     
      ## t/unit-tests/u-reftable-block.c ##
     @@ t/unit-tests/u-reftable-block.c: void test_reftable_block__corrupt_log_block_size(void)
    - 	block_writer_release(&writer);
    + 	reftable_block_release(&block);
      	reftable_buf_release(&data);
      }
     +
     +void test_reftable_block__corrupt_block_size(void)
     +{
     +	struct reftable_block_source source = { 0 };
    -+	struct block_writer writer = {
    -+		.last_key = REFTABLE_BUF_INIT,
    -+	};
     +	struct reftable_record rec = {
     +		.type = REFTABLE_BLOCK_TYPE_REF,
     +		.u.ref = {
    @@ t/unit-tests/u-reftable-block.c: void test_reftable_block__corrupt_log_block_siz
     +		},
     +	};
     +	struct reftable_block block = { 0 };
    -+	struct reftable_buf data;
    -+
    -+	data.len = 1024;
    -+	REFTABLE_CALLOC_ARRAY(data.buf, data.len);
    -+	cl_assert(data.buf != NULL);
    ++	struct reftable_buf data = REFTABLE_BUF_INIT;
     +
    -+	cl_must_pass(block_writer_init(&writer, REFTABLE_BLOCK_TYPE_REF,
    -+				       (uint8_t *) data.buf, data.len,
    -+				       0, hash_size(REFTABLE_HASH_SHA1)));
    -+	cl_must_pass(block_writer_add(&writer, &rec));
    -+	cl_assert(block_writer_finish(&writer) > 0);
    ++	cl_reftable_write_block(&data, REFTABLE_BLOCK_TYPE_REF, &rec, 1);
     +
     +	/*
     +	 * The block size is stored as a big-endian 24-bit integer right after
    @@ t/unit-tests/u-reftable-block.c: void test_reftable_block__corrupt_log_block_siz
     +			  REFTABLE_FORMAT_ERROR);
     +
     +	reftable_block_release(&block);
    -+	block_writer_release(&writer);
     +	reftable_buf_release(&data);
     +}
 7:  3c022a4f97 !  8:  872eca67bb reftable/block: fix OOB read with bogus restart count
    @@ reftable/block.c: int reftable_block_init(struct reftable_block *block,
     
      ## t/unit-tests/u-reftable-block.c ##
     @@ t/unit-tests/u-reftable-block.c: void test_reftable_block__corrupt_block_size(void)
    - 	block_writer_release(&writer);
    + 	reftable_block_release(&block);
      	reftable_buf_release(&data);
      }
     +
     +void test_reftable_block__corrupt_restart_count(void)
     +{
     +	struct reftable_block_source source = { 0 };
    -+	struct block_writer writer = {
    -+		.last_key = REFTABLE_BUF_INIT,
    -+	};
     +	struct reftable_record rec = {
     +		.type = REFTABLE_BLOCK_TYPE_REF,
     +		.u.ref = {
    @@ t/unit-tests/u-reftable-block.c: void test_reftable_block__corrupt_block_size(vo
     +		},
     +	};
     +	struct reftable_block block = { 0 };
    -+	struct reftable_buf data;
    ++	struct reftable_buf data = REFTABLE_BUF_INIT;
     +	int block_size;
     +
    -+	data.len = 1024;
    -+	REFTABLE_CALLOC_ARRAY(data.buf, data.len);
    -+	cl_assert(data.buf != NULL);
    -+
    -+	cl_must_pass(block_writer_init(&writer, REFTABLE_BLOCK_TYPE_REF,
    -+				       (uint8_t *) data.buf, data.len,
    -+				       0, hash_size(REFTABLE_HASH_SHA1)));
    -+	cl_must_pass(block_writer_add(&writer, &rec));
    -+	block_size = block_writer_finish(&writer);
    -+	cl_assert(block_size > 0);
    ++	block_size = cl_reftable_write_block(&data, REFTABLE_BLOCK_TYPE_REF, &rec, 1);
     +
     +	/*
     +	 * Corrupt the restart count to claim a bogus number of restart points.
    @@ t/unit-tests/u-reftable-block.c: void test_reftable_block__corrupt_block_size(vo
     +			  REFTABLE_FORMAT_ERROR);
     +
     +	reftable_block_release(&block);
    -+	block_writer_release(&writer);
     +	reftable_buf_release(&data);
     +}
 8:  af5697b85b =  9:  c82d51c163 reftable/block: fix use of uninitialized memory when binsearch fails
 9:  e9d4eca613 ! 10:  16e1087a66 reftable/block: fix OOB read with bogus restart offset
    @@ reftable/block.c: static int restart_needle_less(size_t idx, void *_args)
     
      ## t/unit-tests/u-reftable-block.c ##
     @@ t/unit-tests/u-reftable-block.c: void test_reftable_block__corrupt_restart_count(void)
    - 	block_writer_release(&writer);
    + 	reftable_block_release(&block);
      	reftable_buf_release(&data);
      }
     +
     +void test_reftable_block__corrupt_restart_offset(void)
     +{
     +	struct reftable_block_source source = { 0 };
    -+	struct block_writer writer = {
    -+		.last_key = REFTABLE_BUF_INIT,
    -+	};
     +	struct reftable_record rec = {
     +		.type = REFTABLE_BLOCK_TYPE_REF,
     +		.u.ref = {
    @@ t/unit-tests/u-reftable-block.c: void test_reftable_block__corrupt_restart_count
     +	struct reftable_block block = { 0 };
     +	struct block_iter it = BLOCK_ITER_INIT;
     +	struct reftable_buf want = REFTABLE_BUF_INIT;
    -+	struct reftable_buf data;
    -+
    -+	data.len = 1024;
    -+	REFTABLE_CALLOC_ARRAY(data.buf, data.len);
    -+	cl_assert(data.buf != NULL);
    ++	struct reftable_buf data = REFTABLE_BUF_INIT;
     +
    -+	cl_must_pass(block_writer_init(&writer, REFTABLE_BLOCK_TYPE_REF,
    -+				       (uint8_t *) data.buf, data.len,
    -+				       0, hash_size(REFTABLE_HASH_SHA1)));
    -+	cl_must_pass(block_writer_add(&writer, &rec));
    -+	cl_assert(block_writer_finish(&writer) > 0);
    ++	cl_reftable_write_block(&data, REFTABLE_BLOCK_TYPE_REF, &rec, 1);
     +
     +	block_source_from_buf(&source, &data);
     +	cl_must_pass(reftable_block_init(&block, &source, 0, 0, data.len,
    @@ t/unit-tests/u-reftable-block.c: void test_reftable_block__corrupt_restart_count
     +	reftable_buf_release(&want);
     +	block_iter_close(&it);
     +	reftable_block_release(&block);
    -+	block_writer_release(&writer);
     +	reftable_buf_release(&data);
     +}
10:  4bb729aeb0 = 11:  63dd98f908 reftable/table: fix NULL pointer access when seeking to bogus offsets
11:  e3bca6af6e = 12:  32696a01bc reftable/table: fix OOB read on truncated table

--- base-commit: ab776a62a78576513ee121424adb19597fbb7613 change-id: 20260623-pks-reftable-hardening-f54de69fea63

Previous: Patrick SteinhardtNext: Patrick Steinhardt
Message 15 of 48 in “reftable: harden against corrupted tables”
  1. 00/11 reftable: harden against corrupted tablesPatrick Steinhardt, Jun 24, 2026
  2. 01/11 meson: support building fuzzers with libFuzzerPatrick Steinhardt, Jun 24, 2026
  3. 02/11 oss-fuzz: add fuzzer for parsing reftablesPatrick Steinhardt, Jun 24, 2026
  4. 03/11 reftable/basics: fix OOB read on binary search of empty rangePatrick Steinhardt, Jun 24, 2026
  5. 04/11 reftable/record: don't abort when decoding invalid ref value typePatrick Steinhardt, Jun 24, 2026
  6. 05/11 reftable/block: fix OOB write with bogus inflated log sizePatrick Steinhardt, Jun 24, 2026
  7. Christian CouderJun 26, 2026
  8. Patrick SteinhardtJun 29, 2026
  9. 06/11 reftable/block: fix OOB read with bogus block sizePatrick Steinhardt, Jun 24, 2026
  10. 07/11 reftable/block: fix OOB read with bogus restart countPatrick Steinhardt, Jun 24, 2026
  11. 08/11 reftable/block: fix use of uninitialized memory when binsearch failsPatrick Steinhardt, Jun 24, 2026
  12. 09/11 reftable/block: fix OOB read with bogus restart offsetPatrick Steinhardt, Jun 24, 2026
  13. 10/11 reftable/table: fix NULL pointer access when seeking to bogus offsetsPatrick Steinhardt, Jun 24, 2026
  14. 11/11 reftable/table: fix OOB read on truncated tablePatrick Steinhardt, Jun 24, 2026
  15. 00/12 reftable: harden against corrupted tablesPatrick Steinhardt, Jun 29, 2026
  16. 01/12 meson: support building fuzzers with libFuzzerPatrick Steinhardt, Jun 29, 2026
  17. 02/12 oss-fuzz: add fuzzer for parsing reftablesPatrick Steinhardt, Jun 29, 2026
  18. 03/12 reftable/basics: fix OOB read on binary search of empty rangePatrick Steinhardt, Jun 29, 2026
  19. 04/12 reftable/record: don't abort when decoding invalid ref value typePatrick Steinhardt, Jun 29, 2026
  20. 05/12 t/unit-tests: introduce test helper to write reftable blocksPatrick Steinhardt, Jun 29, 2026
  21. Junio C HamanoJun 30, 2026
  22. Christian CouderJul 2, 2026
  23. Junio C HamanoJul 3, 2026
  24. 06/12 reftable/block: fix OOB write with bogus inflated log sizePatrick Steinhardt, Jun 29, 2026
  25. Toon ClaesJul 3, 2026
  26. Patrick SteinhardtJul 3, 2026
  27. 07/12 reftable/block: fix OOB read with bogus block sizePatrick Steinhardt, Jun 29, 2026
  28. Toon ClaesJul 3, 2026
  29. Patrick SteinhardtJul 3, 2026
  30. 08/12 reftable/block: fix OOB read with bogus restart countPatrick Steinhardt, Jun 29, 2026
  31. 09/12 reftable/block: fix use of uninitialized memory when binsearch failsPatrick Steinhardt, Jun 29, 2026
  32. 10/12 reftable/block: fix OOB read with bogus restart offsetPatrick Steinhardt, Jun 29, 2026
  33. 11/12 reftable/table: fix NULL pointer access when seeking to bogus offsetsPatrick Steinhardt, Jun 29, 2026
  34. 12/12 reftable/table: fix OOB read on truncated tablePatrick Steinhardt, Jun 29, 2026
  35. 00/12 reftable: harden against corrupted tablesPatrick Steinhardt, Jul 3, 2026
  36. 01/12 meson: support building fuzzers with libFuzzerPatrick Steinhardt, Jul 3, 2026
  37. 02/12 oss-fuzz: add fuzzer for parsing reftablesPatrick Steinhardt, Jul 3, 2026
  38. 03/12 reftable/basics: fix OOB read on binary search of empty rangePatrick Steinhardt, Jul 3, 2026
  39. 04/12 reftable/record: don't abort when decoding invalid ref value typePatrick Steinhardt, Jul 3, 2026
  40. 05/12 t/unit-tests: introduce test helper to write reftable blocksPatrick Steinhardt, Jul 3, 2026
  41. 06/12 reftable/block: fix OOB write with bogus inflated log sizePatrick Steinhardt, Jul 3, 2026
  42. 07/12 reftable/block: fix OOB read with bogus block sizePatrick Steinhardt, Jul 3, 2026
  43. 08/12 reftable/block: fix OOB read with bogus restart countPatrick Steinhardt, Jul 3, 2026
  44. 09/12 reftable/block: fix use of uninitialized memory when binsearch failsPatrick Steinhardt, Jul 3, 2026
  45. 10/12 reftable/block: fix OOB read with bogus restart offsetPatrick Steinhardt, Jul 3, 2026
  46. 11/12 reftable/table: fix NULL pointer access when seeking to bogus offsetsPatrick Steinhardt, Jul 3, 2026
  47. 12/12 reftable/table: fix OOB read on truncated tablePatrick Steinhardt, Jul 3, 2026
  48. Toon ClaesJul 8, 2026

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.