Fix crash when inserting invalid integer into DATETIME column with DuckDB engine - #134
Merged
Merged
Conversation
…ckDB engine Fixes alibaba#131 Description =========== - Server crashes with assertion failure when executing: INSERT IGNORE INTO t (col1) VALUES (57399) where col1 is a DATETIME column on a DuckDB engine table. - The assertion `mon > 0 && mon < 13 && year <= 9999` in sec_since_epoch() (sql/tztime.cc:356) fails because the MYSQL_TIME struct contains month=0. - InnoDB handles this case gracefully by truncating to zero date with a warning, but DuckDB engine crashes. Cause ===== - MySQL's SQL layer converts the invalid integer 57399 to a zero date (0000-00-00 00:00:00) via number_to_datetime() -> reset(), setting month=0. - In the DuckDB write path, DeltaAppender::append_mysql_field() for MYSQL_TYPE_DATETIME2 calls TIME_to_gmt_sec() without validating the MYSQL_TIME struct, which triggers the assertion in sec_since_epoch(). Fix === - Add a zero/invalid date check (tm.month == 0) in the MYSQL_TYPE_DATETIME2 branch of DeltaAppender::append_mysql_field() before calling TIME_to_gmt_sec(). - When a zero date is detected, compute the timestamp directly using calc_daynr(), consistent with the existing MYSQL_TYPE_NEWDATE handling. - Valid dates (month in [1, 12]) continue to use the original TIME_to_gmt_sec() path.
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #131
Description
mon > 0 && mon < 13 && year <= 9999in sec_since_epoch() (sql/tztime.cc:356) fails because the MYSQL_TIME struct contains month=0.Cause
Fix