Ticket #136 (closed defect: fixed)
Problem overwritting Reader's dataoffset due to VLR
| Reported by: | mrosen | Owned by: | hobu |
|---|---|---|---|
| Priority: | major | Milestone: | 1.2.1 |
| Component: | General | Version: | 1.2 |
| Keywords: | Cc: | ||
| LAS Format Version: | Not Applicable |
Description
I recently tracked down a problem to what I believe is a failure in the way LASReader manages it's data offset pointer.
LASReader::Init first reads the header common fields and sets the data offset appropriately. Then it tells it's impl to ReadVLR(m_header). That sounds right but has the side effect of updating the header's data offset. While this bookkeeping is necessary for a Writer, for a Reader this behavior is wrong since it is possible that the point data will not immedately follow the VLRs. Indeed the 1.0 spec advises writers "it is recommended that additional space be allocated to the variable length header space, so that additional variable length data can be added after the initial data is written."
In any case, no harm is really done yet since the Reader still has the original offset it read when it first parsed the header. However, the last thing that Init does is to reset the Header and this flushes the updated data offset from the header to the reader where it potentially (and in some cases, actually) corrupts the reading of point data.
void LASReader::Init()
{
bool ret = m_pimpl->ReadHeader(m_header);
if (!ret)
throw std::runtime_error("public header block reading failure");
ret = m_pimpl->ReadVLR(m_header);
if (!ret)
throw std::runtime_error("public vlr header block reading failure");
m_pimpl->ReadGeoreference(m_header);
// inappropriate for a reader? m_pimpl->Reset(m_header);
}
