dompdf / php-font-lib

A library to read, parse, export and make subsets of different types of font files.
GNU Lesser General Public License v2.1
1.73k stars 256 forks source link

Fixes "strftime() expects parameter 2 to be integer, float given" PHP Warning. #43

Closed pocketarc closed 8 years ago

pocketarc commented 8 years ago

When using DejaVu Sans in dompdf on a 32-bit system, $this->readUInt32(); would often return values outside of the valid integer range, which would turn them into floats, which strftime doesn't like. 64-bit systems don't have this problem.

This code just overrides that for values outside of the valid integer range. It doesn't solve the problem, but readLongDateTime() seems like it has very little use and in these circumstances I'd rather it return an invalid date/time than throw a PHP error. Thoughts?

barryvdh commented 8 years ago

I've had reports with a similar issue in https://github.com/barryvdh/laravel-dompdf/issues/190 on PHP 7.0.2

pocketarc commented 8 years ago

I've had another error where "strftime() expects parameter 2 to be long, string given", and I dug deeper to see what exactly the use of readLongDateTime() is. It seems like it's just used to set created/modified dates for fonts. So when things go wrong with reading the date, I've changed the code to just set the timestamp to 0 and move on. It doesn't affect anything negatively, and it stops warnings from showing up.

I still would like to dig deeper into this and figure out why exactly it's failing to read the dates, but that'll have to wait till I have a bit of free time.

if (is_string($date) || $date > PHP_INT_MAX || $date < PHP_INT_MIN) {
  $date = 0;
}