Review main Merged

65396[TASK] Replace string parsing in Message with unpack

Claus Due CR +2 V +2 Easy +20 −19 updated 02/25/21, 17:01

Commit message

Replaces an inefficient string parsing using strlen, for
and ord, to use unpack instead. Saves one call to strlen
per header, and potentially thousands of calls to ord
per request.

The same strategy is used in Message->filter, however,
this method does not appear to be used so the unpack
change is only applied in isValidHeaderValue.

Review

  • Code review CR +2 Done
    • Christian Kuhn +2
    • Oli Bartsch +1
  • Verified V +2 Done
    • Christian Kuhn +2
    • Oli Bartsch +1
    • TYPO3com +1 CI
    • core-ci +1 CI

Issues 1

Files 2

Review log 1924

  1. Claus Due uploaded patch set 1 08/20/20, 15:57

  2. TYPO3com voted on patch set 1 V +1 08/20/20, 16:08 Completed build in 10m 41s on Thu, 20 Aug, 04:08 PM Test Summary: 72996 passed Find logs and detail information at https://bamboo.typo3.com/browse/CORE-GTC-4782

  3. Andreas Kienast voted on patch set 1 CR +1 08/21/20, 16:34

  4. Jörg Bösche voted on patch set 1 CR +1 02/11/21, 19:19

  5. Richard Haeser voted on patch set 1 CR +1 02/12/21, 09:06

  6. Guido Schmechel voted on patch set 1 CR +1 02/21/21, 11:47

  7. Oliver Hader commented on patch set 1 02/22/21, 09:26

    There are no tests for this method, correct?
  8. Claus Due commented on patch set 1 02/22/21, 09:49

    Reply

    This should trigger for literally any acceptance test, since it is the base class of both Request and Response. \TYPO3\CMS\Core\Tests\Unit\Http\MessageTest also exists and runs successfully; it does not test the "filter" method explicitly, but it does test the "isValidHeaderValue" method in all tests that construct a Message using ->withHeader and has two methods that explicitly test for the exception that is thrown if "isValidHeaderValue" returns false. I'd say this is pretty well covered ;)
  9. Oliver Hader commented on patch set 1 02/22/21, 10:44

    Reply

    Ok, looking into https://github.com/TYPO3/TYPO3.CMS/blob/master/typo3/sysext/core/Tests/Unit/Http/ResponseTest.php#L208-L224 I'd say it does not cover the parts modified in this patch-set at all ;-) (since the existence of "\r\n" triggered returning `false` already)
  10. Claus Due commented on patch set 1 02/22/21, 10:52

    Reply

    The test in ResponseTest is slightly misplaced since it is actually testing the base method on Message, not a method on Response. True, ResponseTest does not cover the changed lines since all the fail-cases are only \r and \n. However, MessageTest *does* cover it since it contains a test case with a \t that isn't covered by the early return by calling strpbrk($value, "\r\n").
  11. Claus Due commented on patch set 1 02/22/21, 11:00

    Reply

    Strike that - this case would actually fail early because it also contains line break and carriage return. I can add a case here that tests specifically for non-LB/CR chars.
  12. Claus Due uploaded patch set 2 02/22/21, 11:11

  13. TYPO3com voted on patch set 2 V -1 02/22/21, 11:17 Completed build in 06m 36s on Mon, 22 Feb, 11:17 AM Test Summary: 1 of 32945 failed Find logs and detail information at https://bamboo.typo3.com/browse/CORE-GTC-9654

  14. Claus Due commented on patch set 2 02/22/21, 11:23

    Message.php:467

    This method is kind of weird. First, anything that contains a LF or CR is rejected. But below, both of those characters are allowed by the in_array check. I am pushing a change to avoid this in_array check by and making the condition below only check if $ascii < 32 || $ascii === 9 || $ascii === 127 || $ascii > 254. Sanity check me please: should \t actually be allowed? It appears from this method that it is allowed.
  15. Claus Due commented on patch set 2 02/22/21, 11:25

    Message.php:467 Reply Unresolved

    > $ascii < 32 || $ascii === 9 || $ascii === 127 || $ascii > 254. ($ascii < 32 && $ascii !== 9) || $ascii === 127 || $ascii > 254 of course.
  16. Claus Due uploaded patch set 3 02/22/21, 11:27

  17. TYPO3com voted on patch set 3 V +1 02/22/21, 11:33 Completed build in 06m 36s on Mon, 22 Feb, 11:33 AM Test Summary: 32704 passed Find logs and detail information at https://bamboo.typo3.com/browse/CORE-GTC-9655

  18. Christian Kuhn uploaded patch set 4 02/25/21, 16:43

  19. Christian Kuhn commented on patch set 4 V +1 CR +1 02/25/21, 16:44

    removing v9: this is not critical.
  20. Oli Bartsch voted on patch set 4 V +1 CR +1 02/25/21, 16:46

  21. TYPO3com voted on patch set 4 V +1 02/25/21, 16:52 Completed build in 09m 19s on Thu, 25 Feb, 04:52 PM Test Summary: 32726 passed Find logs and detail information at https://bamboo.typo3.com/browse/CORE-GTC-9728

  22. core-ci voted on patch set 4 V +1 02/25/21, 16:53 Core CI is happy: https://core.b13.com/typo3-core/typo3.cms/-/pipelines/1009

  23. Christian Kuhn voted on patch set 4 V +2 CR +2 02/25/21, 17:00

  24. Christian Kuhn merged patch set 5 02/25/21, 17:01