Skip to content
/ server Public

MDEV-38791: Disallow duplicate weekday formats in TO_DATE#4810

Open
alexDiaconuAlex wants to merge 1 commit intoMariaDB:12.3from
alexDiaconuAlex:MDEV-38791-fix-12.3
Open

MDEV-38791: Disallow duplicate weekday formats in TO_DATE#4810
alexDiaconuAlex wants to merge 1 commit intoMariaDB:12.3from
alexDiaconuAlex:MDEV-38791-fix-12.3

Conversation

@alexDiaconuAlex
Copy link

@alexDiaconuAlex alexDiaconuAlex commented Mar 15, 2026

Problem

When using TO_DATE with sql_mode='ORACLE', providing duplicate weekday format specifiers (such as 'DAY DY') did not throw an error during the format string parsing phase.

Solution

Added duplicate format checks for weekday specifiers in parse_format_string() (inside sql/item_timefunc.cc).

Now, inputs like SELECT TO_DATE('Monday Mon', 'DAY DY') FROM DUAL; correctly fail early and return ERROR 3047 (HY000): Invalid argument error: date format not recognized at DY in function to_date.

Reported-by: Elena Stepanova elenastepanova@github

@alexDiaconuAlex alexDiaconuAlex force-pushed the MDEV-38791-fix-12.3 branch 2 times, most recently from ac82c2b to f99b235 Compare March 15, 2026 19:02
@gkodinov gkodinov added the External Contribution All PRs from entities outside of MariaDB Foundation, Corporation, Codership agreements. label Mar 16, 2026
Copy link
Member

@gkodinov gkodinov left a comment

Choose a reason for hiding this comment

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

Thank you for your contribution! This is a preliminary review.

Please make the commit message compliant with CODING_STANDARDS.md

}
else if (tmp1 == 'Y')
{
if (for_to_date && formats_used(&used, FMT_DAY))
Copy link
Member

Choose a reason for hiding this comment

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

You sure you just need to check for FMT_DAY? IMHO more is needed.

{
if (ptr + 2 == end || my_toupper(system_charset_info, *(ptr+2)) != 'Y')
goto error;
if (for_to_date && formats_used(&used, FMT_DAY))
Copy link
Member

Choose a reason for hiding this comment

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

ditto here

@@ -0,0 +1,4 @@
SET sql_mode='ORACLE';

SELECT TO_DATE('Monday Mon', 'DAY DY');
Copy link
Member

Choose a reason for hiding this comment

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

Please add all of the queries mentioned into the JIRa. Also please extend the test suite will all the additional combos you can think of. E.g. IYYY etc.

The Oracle-mode TO_DATE() function incorrectly parsed strings containing
duplicate or conflicting format specifiers (e.g., 'YYYY YYYY', 'DAY DY',
or 'AM PM') without throwing an ER_STD_INVALID_ARGUMENT error.

This patch introduces family-based conflict checks in item_timefunc.cc
during format string parsing. It leverages the formats_used bitmask to
ensure that specifiers sharing the same logical time bucket strictly
block each other:

  * Year family: Y, YY, YYY, YYYY, RR, RRRR, SYYYY
  * Month family: MM, MON, MONTH, RM, DDD
  * Day family: D, DD, DY, DAY, DDD
  * Hour family: HH, HH12, HH24
  * Meridian family: AM, PM, A.M., P.M.

Compatible specifiers, such as YYYY and DDD (Year and Day of Year),
remain unaffected and parse successfully. A comprehensive MTR test
suite has been added to cover standard and edge-case conflicts.

Reported-by: Elena Stepanova <elenastepanova@github>

Signed-off-by: Alexandru Diaconu <alexandrudiaconu93@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

External Contribution All PRs from entities outside of MariaDB Foundation, Corporation, Codership agreements.

Development

Successfully merging this pull request may close these issues.

2 participants