Repository navigation
GD readers : Fixed valid files rejected because of PHP deprecations - #15
mkantautas wants to merge 2 commits into
Conversation
|
Thanks for the fix! It does solve the PHP 8.5 failure for WMF files without a A few remarks: 1. The root cause is still there ( 2. The EMF reader has the same issue ( 3. Default units per inch when no map mode is set ( 4. Minor: duplicated fallback Or move the value into a constant. 5. Changelog |
- `PhpOffice\WMF\Reader\WMF\GD` & `PhpOffice\WMF\Reader\EMF\GD` : the error handler returns false for `E_DEPRECATED` & `E_USER_DEPRECATED`, so a deprecation no longer rejects a valid file or makes an EMF+ file fall back to its EMF records - `PhpOffice\WMF\Reader\WMF\GD` : the default of 1440 units per inch is a constant, used by the placeable header and by the window - `testLoadStandardWMF` checks that `burger.wmf` without its placeable header (no `META_SETMAPMODE` record) loads without any error, and replaces `testLoadStandardWMFWithoutMapMode` - Changelog entries in `docs/changes/0.2.1.md`
PhpOffice\WMF\Reader\WMF\GD : Fixed standard WMF files without map mode on PHP 8.5|
Thanks for the review. Pushed f7d4c60:
Tests on PHP 8.5.8, 8.1.32 and 7.4.33: the only failures are tests that need imagick (not installed here), the same set as on master. phpstan and php-cs-fixer report no issues. |
A standard WMF file (no placeable header) without a
META_SETMAPMODErecord leaves$mapModenull ingetWindowBounds(), and$unitsPerInch[$mapMode] ?? 1440uses null as an array offset, which PHP 8.5 deprecates. The error handlers of both GD readers turned every reported error intoWMFException('Reader : Invalid file'), deprecations included, so the file failed to load. In the EMF reader, a deprecation raised while drawing EMF+ records would make the file fall back to its EMF records.PhpOffice\WMF\Reader\WMF\GD&PhpOffice\WMF\Reader\EMF\GD: the error handlers returnfalseforE_DEPRECATEDandE_USER_DEPRECATED, so PHP reports them and the file loads.PhpOffice\WMF\Reader\WMF\GD: the units per inch are looked up with$mapMode ?? 0. Files without a map mode keep 1440 units per inch, now in theDEFAULT_UNITS_PER_INCHconstant, also used for a placeable header without units.docs/changes/0.2.1.md.This is item 2 of #13.
Tests:
testLoadStandardWMFloadsburger.wmfwithout its placeable header witherror_reporting(E_ALL)and checks that no error is raised; it fails on PHP 8.5 without the fix.testLoadWithDeprecation(WMF and EMF readers) triggers anE_USER_DEPRECATEDwhile reading and checks that the file loads, and that the EMF+ records oflibemf2svg/emf/test-000.emfare still drawn; it fails without the error handler change. Full suite on PHP 8.5.8, 8.1.32 and 7.4.33: the only failures are tests that need the imagick extension (not installed locally), the same set as on master. phpstan and php-cs-fixer report no issues.