Skip to content

Validate .rows in tibble() - #1697

Open
sims1253 wants to merge 2 commits into
tidyverse:mainfrom
sims1253:fix/ry-audit-round2
Open

sims1253 wants to merge 2 commits into
tidyverse:mainfrom
sims1253:fix/ry-audit-round2

Conversation

@sims1253

@sims1253 sims1253 commented Sep 9, 2026

Copy link
Copy Markdown

tibble_quos() in R/tibble.R copies .rows into first_size without checking it. The first evaluated column then hits first_size == 1L && current_size != 1L, so a vector .rows fails inside && with a base R message, and other bad values surface as errors about something else:

tibble(a = 1:3, .rows = c(1L, 5L))
#> Error: 'length = 2' in coercion to 'logical(1)'
tibble(a = 1:3, .rows = 1.5)
#> Error: Tibble columns must have compatible sizes.
tibble(.rows = -1)
#> Error: `nrow` must be a nonnegative whole number smaller than 2^31.

This PR validates .rows once, before the column loop. It must be NULL or a single non-negative whole number. Anything else goes through a new abort_bad_rows_arg() helper that follows the existing tibble_abort(problems(...)) pattern, so the condition gets the class tibble_error_bad_rows_arg.

All three calls now fail the same way, with the offending value on the second line:

Error in `tibble()`:
! `.rows` must be `NULL` or a single nonnegative whole number.
x `.rows` is c(1L, 5L).

Found during my most recent ry audit.

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.

1 participant