Skip to content

fix(core): handle i64::MIN in PRAGMA cache_size to prevent panic (#5250)#5272

Open
HarshKumarSahni wants to merge 1 commit intotursodatabase:mainfrom
HarshKumarSahni:fix/pragma-cache-size-panic
Open

fix(core): handle i64::MIN in PRAGMA cache_size to prevent panic (#5250)#5272
HarshKumarSahni wants to merge 1 commit intotursodatabase:mainfrom
HarshKumarSahni:fix/pragma-cache-size-panic

Conversation

@HarshKumarSahni
Copy link

Description

This PR fixes a panic that occurs when PRAGMA cache_size is set to i64::MIN (-9223372036854775808).

The issue was caused by an implementation detail where i64::MIN.abs() was called, resulting in an overflow panic because i64::MIN's absolute value cannot be represented in a signed 64-bit integer.

Changes:

  • Modified update_cache_size in core/translate/pragma.rs to explicitly handle i64::MIN by clamping it to i64::MAX before processing.
  • Added a new regression test test_pragma_cache_size_i64_min in tests/integration/pragma.rs to verify the fix.

Motivation and context

This fixes issue #5250.
Previously, executing PRAGMA cache_size=-9223372036854775808 would crash the database process with an "attempt to negate with overflow" error. This PR ensures the database handles this edge case gracefully instead of crashing.

Closes #5250

Description of AI Usage

I utilized the Antigravity AI assistant to help diagnose and resolve this issue.

Copy link

@turso-bot turso-bot bot left a comment

Choose a reason for hiding this comment

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

Please review @pereman2

assert_eq!(*count, 7, "all inserts should have succeeded");
}

#[turso_macros::test(mvcc)]
Copy link
Collaborator

Choose a reason for hiding this comment

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

could you please replace this with a new test case in our .sqltest files?

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.

PRAGMA cache_size Panics on i64::MIN Due to Negate Overflow

2 participants