mirror of
https://github.com/LadybirdBrowser/ladybird
synced 2026-04-27 02:05:07 +02:00
LibSQL: Support 64-bit integer values and handle overflow errors
Currently, integers are stored in LibSQL as 32-bit signed integers, even if the provided type is unsigned. This resulted in a series of unchecked unsigned-to-signed conversions, and prevented storing 64-bit values. Further, mathematical operations were performed without similar checks, and without checking for overflow. This changes SQL::Value to behave like SQLite for INTEGER types. In SQLite, the INTEGER type does not imply a size or signedness of the underlying type. Instead, SQLite determines on-the-fly what type is needed as values are created and updated. To do so, the SQL::Value variant can now hold an i64 or u64 integer. If a specific type is requested, invalid conversions are now explictly an error (e.g. converting a stored -1 to a u64 will fail). When binary mathematical operations are performed, we now try to coerce the RHS value to a type that works with the LHS value, failing the operation if that isn't possible. Any overflow or invalid operation (e.g. bitshifting a 64-bit value by more than 64 bytes) is an error.
This commit is contained in:
Notes:
sideshowbarker
2024-07-17 03:15:15 +09:00
Author: https://github.com/trflynn89 Commit: https://github.com/SerenityOS/serenity/commit/72e41a7dbd Pull-request: https://github.com/SerenityOS/serenity/pull/16427 Reviewed-by: https://github.com/davidot ✅
@@ -119,7 +119,7 @@ ResultOr<ResultSet> Select::execute(ExecutionContext& context) const
|
||||
|
||||
auto limit = TRY(m_limit_clause->limit_expression()->evaluate(context));
|
||||
if (!limit.is_null()) {
|
||||
auto limit_value_maybe = limit.to_u32();
|
||||
auto limit_value_maybe = limit.to_int<size_t>();
|
||||
if (!limit_value_maybe.has_value())
|
||||
return Result { SQLCommand::Select, SQLErrorCode::SyntaxError, "LIMIT clause must evaluate to an integer value"sv };
|
||||
|
||||
@@ -129,7 +129,7 @@ ResultOr<ResultSet> Select::execute(ExecutionContext& context) const
|
||||
if (m_limit_clause->offset_expression() != nullptr) {
|
||||
auto offset = TRY(m_limit_clause->offset_expression()->evaluate(context));
|
||||
if (!offset.is_null()) {
|
||||
auto offset_value_maybe = offset.to_u32();
|
||||
auto offset_value_maybe = offset.to_int<size_t>();
|
||||
if (!offset_value_maybe.has_value())
|
||||
return Result { SQLCommand::Select, SQLErrorCode::SyntaxError, "OFFSET clause must evaluate to an integer value"sv };
|
||||
|
||||
|
||||
Reference in New Issue
Block a user