Hacktoberfest 2026: the issues maintainers tagged for October, open and beginner-friendly. Browse Hacktoberfest issues

`primeSieve(31627)` reads past the precomputed prime table

Open Beginner friendly
#82 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
72/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
cpp, r
Domain
backend

Research direction

Start in src/Eratosthenes.cpp, in the table shortcut loop at lines 66-72 of PrimeSieveSmall(): compare ind against the actual length of smallPrimeBase so traversal stops at the boundary while still emitting 31,627. Then extend the existing R test that uses primeSieve(31625, 31630) with endpoint cases at 31,627 and its neighbours, in the package's testthat suite. Done means the endpoint test passes under ordinary build and under AddressSanitizer, with no read past the array.

Written by the indexing model from the issue text.

Description

PrimeSieveSmall() reads beyond smallPrimeBase when the upper bound equals the table’s final entry, 31,627.

The affected R call is:

RcppAlgos::primeSieve(31627)

The table shortcut uses this loop:

https://github.com/jwood000/RcppAlgos/blob/a7dde4327a88bda94dd297fca271be35d6bc80f9/src/Eratosthenes.cpp#L66-L72

After emitting the final prime, ind becomes 3402. The next condition reads element 3402 of the 3402-element array.

This is undefined behavior, even when an ordinary build appears to return the expected primes.

Verification

A standalone build of the unchanged native implementation, using Apple Clang 17 with AddressSanitizer, reported a global-buffer-overflow: a four-byte read immediately after smallPrimeBase.

The native reproduction called PrimeSieve::PrimeSieveMain<int> with bounds 1, 31627, one thread, and initially empty output vectors. The sanitizer finding was reproduced through this native entry point, rather than an installed R package.

Expected behavior and follow-up

  • Stop traversal at the table boundary while including 31,627 in the result.
  • Add regression coverage for the exact endpoint and relevant nearby bounds.
  • Verify the correction under AddressSanitizer as well as ordinary tests.

The existing primeSieve(31625, 31630) test takes a different path and does not cover this boundary.

Dominant language
C++
Stars
51
Forks
5
Avg merge
6h 55m
Merged PRs (30d)
8

Getting set up

This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from jwood000/RcppAlgos

All issues in jwood000/RcppAlgos

Similar issues

More C++ issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.