Skip to content

Conversation

@aitap
Copy link
Member

@aitap aitap commented Jan 14, 2026

Check the index for being NA_INTEGER before trying to access it.

Should this also protect from invalid factors? For example, this also currently crashes:

data.table::setattr(structure(integer(999), class = "factor", levels = "a"), "levels", c("b", "b"))

Should this go into 1.18.2?

Fixes: #7595

@aitap aitap requested a review from MichaelChirico as a code owner January 14, 2026 18:49
@codecov
Copy link

codecov bot commented Jan 14, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.02%. Comparing base (d3d0019) to head (22e0f2e).
⚠️ Report is 1 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #7596   +/-   ##
=======================================
  Coverage   99.02%   99.02%           
=======================================
  Files          87       87           
  Lines       16804    16806    +2     
=======================================
+ Hits        16640    16642    +2     
  Misses        164      164           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@github-actions
Copy link

github-actions bot commented Jan 14, 2026

  • HEAD=fix-setattr-crash slower P<0.001 for memrecycle regression fixed in #5463
    Comparison Plot

Generated via commit 22e0f2e

Download link for the artifact containing the test results: ↓ atime-results.zip

Task Duration
R setup and installing dependencies 3 minutes and 15 seconds
Installing different package versions 22 seconds
Running and plotting the test cases 4 minutes and 3 seconds

@aitap
Copy link
Member Author

aitap commented Jan 14, 2026

Test 2361.2 could also signal an error, similar to how base::`levels<-` fails (but doesn't crash) when given such a factor.

@MichaelChirico
Copy link
Member

Should this go into 1.18.2?

I'd say yes, anytime we eliminate a crash it's important to include it ASAP

@MichaelChirico MichaelChirico added this to the 1.18.2 milestone Jan 14, 2026
Copy link
Member

@MichaelChirico MichaelChirico left a comment

Choose a reason for hiding this comment

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

Thanks!

@aitap aitap merged commit 20b463c into master Jan 14, 2026
11 checks passed
@aitap aitap deleted the fix-setattr-crash branch January 14, 2026 19:44
aitap added a commit that referenced this pull request Jan 14, 2026
Check for missing or out of bounds values and set them to NA.
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.

setlevels() doesn't handle missing or out-of-bounds factor values

2 participants