jdavidbakr / mail-tracker

Package for Laravel to inject tracking code into outgoing emails.
MIT License
577 stars 129 forks source link

Missing format specifier at end of string (Fatal PHP 8 compatibility issue) #127

Closed dwhoop55 closed 3 years ago

dwhoop55 commented 3 years ago

When running PHP 8.0.0 there is an issue with the sprintf function in MailTrackerController.php

Steps to reproduce

  1. Have Laravel running with PHP 8.0.0
  2. Install mail-tracker, migrate, and send an email
  3. Open the email, should load image and update database (which it does not)
  4. When manually loading the tracking gif in a browser the issue becomes visible

image

How to fix

That is actually quite simple. I've dig deeper and found that the last byte (59) isn't even in the returned response. Probably only a c missing after the %, so:

Before

$pixel = sprintf('%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%', 71, 73, 70, 56, 57, 97, 1, 0, 1, 0, 128, 255, 0, 192, 192, 192, 0, 0, 0, 33, 249, 4, 1, 0, 0, 0, 0, 44, 0, 0, 0, 0, 1, 0, 1, 0, 0, 2, 2, 68, 1, 0, 59);

After

$pixel = sprintf('%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c', 71, 73, 70, 56, 57, 97, 1, 0, 1, 0, 128, 255, 0, 192, 192, 192, 0, 0, 0, 33, 249, 4, 1, 0, 0, 0, 0, 44, 0, 0, 0, 0, 1, 0, 1, 0, 0, 2, 2, 68, 1, 0, 59);

Comparing the response in a hex editor (curl http://localhost/email/t/hash | hexdump) now shows the last byte (59).

dwhoop55 commented 3 years ago

Fixed in #128

dwhoop55 commented 3 years ago

Thank you! Fixed in 4.0.11 2a631b8b3e6fa1411966aa2a2c86b4be8e544ead