[
https://issues.apache.org/jira/browse/THRIFT-5987?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Jens Geyer resolved THRIFT-5987.
--------------------------------
Fix Version/s: 0.24.0
Assignee: Jens Geyer
Resolution: Fixed
> Fix PHP protocol type-safety bugs in readBool and popContext
> ------------------------------------------------------------
>
> Key: THRIFT-5987
> URL: https://issues.apache.org/jira/browse/THRIFT-5987
> Project: Thrift
> Issue Type: Bug
> Components: PHP - Library
> Reporter: Jens Geyer
> Assignee: Jens Geyer
> Priority: Major
> Fix For: 0.24.0
>
> Time Spent: 20m
> Remaining Estimate: 0h
>
> Three type-safety bugs introduced when native PHP type declarations were
> added to the protocol classes.
> h3. TCompactProtocol::readBool — integer written through a bool-typed
> reference
> {{readBool(?bool &$bool)}} passes {{$bool}} directly to {{readByte(?int
> &$byte)}} in the {{STATE_CONTAINER_READ}} branch. {{readByte}} unpacks a raw
> byte and writes an integer back through the reference, leaving a
> {{?bool}}-declared variable holding an integer value.
> *Fix:* route through a local {{?int $byte}} variable and cast {{(bool)$byte}}
> before assigning to {{$bool}}.
> h3. TJSONProtocol::popContext — nullable array_pop result assigned to
> non-nullable property
> {{popContext()}} does {{$this->context = array_pop($this->contextStack)}}.
> Because the declared type of {{$context}} is the non-nullable
> {{BaseContext}}, a context-stack underflow causes a {{TypeError}} instead of
> behaving gracefully.
> *Fix:* use null-coalescing fallback: {{array_pop(...) ?? new BaseContext()}}.
> h3. TCompactProtocolTest — missing $size assertion in testWriteListBegin /
> testWriteSettBegin
> Both tests changed their {{writeCollectionBegin}} mock expectation from
> {{->with(TType::STRING, 1)}} to {{->with(TType::STRING)}}, silently dropping
> verification that the element count is forwarded correctly.
> *Fix:* restore {{->with(TType::STRING, 1)}} in both test methods.
> See also: https://github.com/apache/thrift/pull/3467
--
This message was sent by Atlassian Jira
(v8.20.10#820010)