Heap corruption in DateTime.strftime() on 32 bit for certain format strings
A bug in DateTime.strftime() on 32-bit systems with a very high precision format string can cause a crash.
- Triaged in 9 hours
- Disclosed after 7 days
(originally send by e-mail on 4 Jun 2016)
Setting a very high precision in the date_strftime_with_tmx() function, the following check (in the STRFTIME macro in date_strftime.c) will not work as expected if 's' >= 0x80000000 (this is the same type of issue as the other vulnerability I submitted).
124 if (start + maxsize < s + precision) { \
125 errno = ERANGE; \
126 return 0; \
127 }
This code causes a crash on my 32 bit system:
require 'date'
d = DateTime.new(2007,11,19,8,37,48,"-06:00")
d.strftime("%2147483647c")
64 bit is probably not affected (strictly technically possible, but unlikely).
Let me know if you need more information.
Guido
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
How it worked
Root cause
Likely an integer overflow in the bounds check when the precision value is large enough to make the sum exceed the maximum signed 32-bit integer, causing the check to pass incorrectly.
Impact
On 32-bit systems, this causes a crash; 64-bit systems are probably not affected.
What the attacker needed
32-bit system; ability to pass a crafted format string to strftime
How it was found
- Create a DateTime object with a specific date and time.
- Call strftime with a format string containing a very large precision value.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
A date formatting function has a bug: a format string with a huge number makes an internal check fail on 32-bit systems, causing a crash.
What is Memory corruption?
Native code reads or writes memory it should not: overflows, use-after-free, type confusion. The core of browser, kernel and parser bugs.