Skip to content

Fix out-of-bounds read in FASTCOVER on small training samples - #4710

Open
eyupcanakman wants to merge 2 commits into
meta:devfrom
eyupcanakman:fix/fastcover-small-samples-4499
Open

eyupcanakman wants to merge 2 commits into
meta:devfrom
eyupcanakman:fix/fastcover-small-samples-4499

Conversation

@eyupcanakman

Copy link
Copy Markdown
Contributor

When every training sample is smaller than the dmer size, FASTCOVER_ctx_init derives nbDmers from the training set, which splitPoint < 1 can shrink below MAX(d, 8) even after the total samples size check passes. The subtraction underflows and the builder reads past the sample buffer (#4499).

It now returns srcSize_wrong for a training set that small, the way the other invalid inputs already do. Adds a unit test in basicUnitTests.

COVER_ctx_init has the same underflow, addressed separately in #4690.

When every training sample is smaller than the dmer size, splitPoint < 1 can shrink the training set below MAX(d, 8) after the total samples size check passes, so nbDmers underflows and FASTCOVER reads past the sample buffer (meta#4499). It now returns srcSize_wrong. Adds a unit test in basicUnitTests. The same underflow in COVER_ctx_init is addressed separately in meta#4690.
@meta-cla meta-cla Bot added the CLA Signed label Jul 13, 2026
Comment thread lib/dictBuilder/fastcover.c Outdated
}

/* Check the training set can hold at least one dmer, otherwise nbDmers underflows below */
if (trainingSamplesSize < MAX(d, sizeof(U64))) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

MAX(d, sizeof(U64) is now referenced multiple times - it deserves to be a named quanity now. readLength would be good here.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done in 233eb64, all three uses go through readLength now.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants