You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@thrift.apache.org by "Christopher Friedt (Jira)" <ji...@apache.org> on 2020/06/20 01:45:00 UTC

[jira] [Updated] (THRIFT-5093) TMemoryBuffer constructor initializes wpos incorrectly

     [ https://issues.apache.org/jira/browse/THRIFT-5093?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Christopher Friedt updated THRIFT-5093:
---------------------------------------
    Description: 
The TMemoryBuffer policy is "OBSERVER" by default in a constructor where an external pointer to memory, and the size of that memory, are passed in. That scenario is for externally managed buffers.

As an observer of a buffer, Thrift should only be able to read. However, previously, `buf.available_read()` would return 0 (and subsequently, `buf.read()` would fail). 

I've added a test as a separate commit, so it's easy to observe the failure and fix. The current behaviour produces the following failure.
{noformat}
TMemoryBufferTest.cpp(141): error: in "TMemoryBufferTest/test_observer": check N == buf.available_read() has failed [1024 != 0]
{noformat}
With this change, Thrift applications that use Memory as a transport are able to read `OBSERVER` buffers as well (as one would expect) and the error above is mitigated.


  was:
The third constructor of TMemoryBuffer incorrectly initializes the write pointer (wpos) to be at the end of the buffer instead of at the front when it calls initCommon(). Looking at references to initCommon(), the wpos parameter is initialized to 0 everywhere else it is used.

https://github.com/apache/thrift/blob/master/lib/cpp/src/thrift/transport/TBufferTransports.h#L535

That causes the branch below to never be taken and therefore data is never written to the buffer.

https://github.com/apache/thrift/blob/master/lib/cpp/src/thrift/transport/TBufferTransports.h#L98

It's a simple one-line fix. Will submit a PR in GitHub.


> TMemoryBuffer constructor initializes wpos incorrectly
> ------------------------------------------------------
>
>                 Key: THRIFT-5093
>                 URL: https://issues.apache.org/jira/browse/THRIFT-5093
>             Project: Thrift
>          Issue Type: Bug
>          Components: C++ - Library
>    Affects Versions: 0.10.0, 0.11.0, 0.12.0, 0.13.0
>            Reporter: Christopher Friedt
>            Priority: Major
>          Time Spent: 2h
>  Remaining Estimate: 0h
>
> The TMemoryBuffer policy is "OBSERVER" by default in a constructor where an external pointer to memory, and the size of that memory, are passed in. That scenario is for externally managed buffers.
> As an observer of a buffer, Thrift should only be able to read. However, previously, `buf.available_read()` would return 0 (and subsequently, `buf.read()` would fail). 
> I've added a test as a separate commit, so it's easy to observe the failure and fix. The current behaviour produces the following failure.
> {noformat}
> TMemoryBufferTest.cpp(141): error: in "TMemoryBufferTest/test_observer": check N == buf.available_read() has failed [1024 != 0]
> {noformat}
> With this change, Thrift applications that use Memory as a transport are able to read `OBSERVER` buffers as well (as one would expect) and the error above is mitigated.



--
This message was sent by Atlassian Jira
(v8.3.4#803005)