Review main Abandoned

67174[BUGFIX] Avoid PHP warning in Extbase Session->hasIdentifier

Claus Due CR 0 V 0 Easy +2 −1 updated 12/18/20, 12:54

Commit message

When Session->hasIdentifier() is called but no instance of
$className has yet been fetched, a PHP warning about
illegal offset type is triggered. This happens because the
isset() check passes:

    $this->identifierMap[$this->getClassIdentifier($className)][$identifier]

But because $this->identifierMap[$this->getClassIdentifier($className)]
in this case is NULL, the reference attempts to access
`null[$identifier]` which is of course not valid.

The problem is prevented by splitting the checked
variable reference into two arguments for isset(),
which in turn returns early if the first of the two
arguments is not set. This prevents the check for
an array key being set on a null value, causing
the PHP warning to no longer be triggered.

Review

  • Code review CR 0
  • Verified V 0

Issues 1

Files 1

Review log 67

  1. Claus Due uploaded patch set 1 12/17/20, 10:44

  2. TYPO3com voted on patch set 1 V +1 12/17/20, 10:53 Completed build in 08m 57s on Thu, 17 Dec, 10:53 AM Test Summary: 32433 passed Find logs and detail information at https://bamboo.typo3.com/browse/CORE-GTC-8225

  3. Oliver Klee voted on patch set 1 CR +1 12/17/20, 18:17

  4. Oli Bartsch commented on patch set 1 CR -1 12/17/20, 20:06

    Hi, I unfortunately can't comprehend this patch. `null[$identifier]` will not lead to this warning. See: https://3v4l.org/uBBVr. Illegal offset type is triggered when you try to use an array or object as array key. But as far as I see, this is not the case here. `$this->identifierMap` is initialized as an empty array. `getClassIdentifier()` will always return a string, since it's type hinted and would therefore lead to type errors otherwise. See this more detailed example: https://3v4l.org/C4o24. The only possibility I see is that an array or object is provided as `$identifier` (Since this parameter is not type-hinted, this would be possible). This however then would be an error on the calling code. However, the question for me is: How can I reproduce this? Sharing the full stake trace would help a lot.
  5. Claus Due commented on patch set 1 12/18/20, 11:48

    Reply

    You are completely right... the fix was actually a false positive that prevented a different issue. Some code in my customer's project was doing Repository->findByUid($object) which meant the $identifier in this code was an object. The warning was only prevented with this merge request, by the coincidence that no instances of $className had been previously loaded - the same problem would happen even with this fix, if that had been the case. I would have noticed this if I had been able to use xdebug but unfortunately the error only happened in production. So I'll close this merge request but leave the issue open. Making the arguments for Session->hasIdentifier() strict would prevent it (and dispatch a much more specific error), as would throwing an exception - but neither of those are appropriate to merge to 9.5 and 10.4 I think. Sorry for wasting time :/
  6. Claus Due abandoned the change 12/18/20, 11:49

    Problem reported in issue is only coincidentally fixed by this change - the true fix has to be either strict argument types for Session->hasIdentifier, or throwing an exception if $identifier is not scalar.
  7. Oli Bartsch commented on patch set 1 12/18/20, 12:54

    Reply Unresolved

    No problem :) I'm glad we could figure this out.