Skip to content

Add Reader/ReadBytes fuzz tests and limits#394

Merged
klauspost merged 8 commits intotinylib:masterfrom
klauspost:add-fuzz-tests
Jun 24, 2025
Merged

Add Reader/ReadBytes fuzz tests and limits#394
klauspost merged 8 commits intotinylib:masterfrom
klauspost:add-fuzz-tests

Conversation

@klauspost
Copy link
Collaborator

@klauspost klauspost commented Jun 24, 2025

  • Fix crash in ReadTimeBytes
  • Limit map/array size on ReadIntfBytes
  • Expose SetMaxRecursionDepth/GetMaxRecursionDepth to manage max recursion depth.
  • Expose SetMaxElements/GetMaxElements to limit array, bin, map and extension sizes.
  • Expose SetMaxStringLength/GetMaxStrLen to limit string/map key sizes.

All of these will allow stricter control over decoding memory usage.

  • Test corpus added.
  • Bumps minimum version to Go 1.22
  • Upgraded golangci-lint to latest version - fixes issues reported.

* Fix crash in ReadTimeBytes
* Limit map/array size on ReadIntfBytes
* Expose `SetMaxRecursionDepth/GetMaxRecursionDepth/RecursiveCall` to manage max recursion depth.
* Expose `SetMaxElements/GetMaxElements` to limit array, bin, map and extension sizes.
* Expose `SetMaxStringLength/GetMaxStrLen` to limit string/map key sizes.

All of these will allow stricter control over decoding memory usage.

Bumps minimum version to Go 1.22
@klauspost klauspost requested review from Copilot and philhofer June 24, 2025 12:51
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds configurable limits to prevent excessive memory usage in decoding, fixes an extension error in ReadTimeBytes, and introduces comprehensive fuzz tests for byte-reading functions.

  • Expose and enforce max recursion depth, element counts, and string length limits on Reader and related functions.
  • Fix crash in ReadTimeBytes by using the correct typ variable in error handling.
  • Add fuzz tests covering Reader and standalone Read*Bytes functions and bump minimum Go version to 1.22.

Reviewed Changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
msgp/read_bytes.go Correct use of typ in extension error and add underflow checks in readMapStrIntfBytesDepth and readIntfBytesDepth.
msgp/read.go Introduce Set/GetMaxRecursionDepth, Set/GetMaxElements, SetMaxStringLength/GetMaxStrLen, enforce limits, and rename recursiveCall.
msgp/json.go Enforce string-length limits in JSON reader helpers.
msgp/extension.go Enforce element-count limits in extension readers.
msgp/errors.go Define new ErrLimitExceeded error.
msgp/fuzz_test.go Add fuzz tests for both Reader methods and standalone byte readers.
go.mod Bump minimum Go version from 1.20 to 1.22.
.github/workflows/validate.yml Update linter matrix to Go 1.24.
.github/workflows/test.yml Update test matrix to include Go 1.24.
Comments suppressed due to low confidence (1)

msgp/read.go:257

  • [nitpick] The getter name GetMaxStrLen is inconsistent with the setter SetMaxStringLength. Consider renaming it to GetMaxStringLength for a clearer and more consistent API.
func (m *Reader) GetMaxStrLen() uint64 {

klauspost and others added 2 commits June 24, 2025 15:56
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@klauspost klauspost merged commit 55a61ad into tinylib:master Jun 24, 2025
4 checks passed
@klauspost klauspost deleted the add-fuzz-tests branch June 24, 2025 16:59
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.

3 participants