Skip to content
Memory corruption Disclosed report Advanced

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.

guido Follow

Originally disclosed on HackerOne

  • 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).

C
124         if (start + maxsize < s + precision) {          \
125             errno = ERANGE;                 \
126             return 0;                       \
127         }

This code causes a crash on my 32 bit system:

Ruby
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

The original report as published on HackerOne, by guido. Images and videos are our own copies; raw HTML is shown as text. View it on HackerOne.

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

  1. Create a DateTime object with a specific date and time.
  2. 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.

More by guido

View all

49 more disclosed reports, best first.

More from Ruby

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Memory corruption

The lesson behind this report.

Native code reads or writes memory it should not: overflows, use-after-free, type confusion. The core of browser, kernel and parser bugs.