Project

General

Profile

Bug #11572

Crash in uncompress for kHuffman

Added by David Adams almost 4 years ago. Updated over 3 years ago.

Status:
Rejected
Priority:
Normal
Category:
-
Target version:
-
Start date:
02/02/2016
Due date:
% Done:

0%

Estimated time:
Spent time:
Occurs In:
Experiment:
-
Co-Assignees:
Duration:

Description

I get a crash in

void UncompressHuffman(const std::vector<short>& adc,
std::vector<short> &uncompressed)

from lardata/RawData/raw.cxx. I believe it is because I have passed an empty vector in my call to

void Uncompress(const std::vector&lt;short&gt;& adc,
std::vector&lt;short&gt; &uncompressed,
int &pedestal,
raw::Compress_t compress)

with compress = raw::kHuffman.

and UncompressHuffman tries to fill uncompress without allocating space:

uncompressed[0] = adc[0];

I believe UncompressHuffman (or Uncompress) should first ensure the vector is of appropriate size.

History

#1 Updated by Jonathan Insler almost 4 years ago

David Adams wrote:

I get a crash in

void UncompressHuffman(const std::vector<short>& adc,
std::vector<short> &uncompressed)

from lardata/RawData/raw.cxx. I believe it is because I have passed an empty vector in my call to

void Uncompress(const std::vector<short>& adc,
std::vector<short> &uncompressed,
int &pedestal,
raw::Compress_t compress)

with compress = raw::kHuffman.

and UncompressHuffman tries to fill uncompress without allocating space:

uncompressed0 = adc0;

I believe UncompressHuffman (or Uncompress) should first ensure the vector is of appropriate size.

This problem predates my involvement with raw.cxx. It looks like the original UncompressHuffman function doesn't resize std::vector<short> uncompressed, so it must be delivered to raw.cxx as the proper size.

#2 Updated by Gianluca Petrillo over 3 years ago

  • Status changed from New to Rejected

The function raw::Uncompress() expects the buffer to be fully allocated. Good old C style (or not so good).
Of course, that is documented nowhere.

I will not change this behaviour, since the uncompress function does not necessarily know the size of the uncompressed data before inflating is completed. Progressively expanding the buffer can be inefficient.
On the other end, the caller one, if the buffer comes from a raw::RawDigit the sample size is known and the caller can resize the buffer to the expected final size.

#3 Updated by Gianluca Petrillo over 3 years ago

I have pushed (develop branch in lardata) inline documentation to Uncompress() and Compress() functions, that are the functions that LArSoft originally supported.
I don't know enough of the current custom to personally support the others.

I believe the whole uncompression system (and maybe the compression too?) should be revisited, formalized and updated.
There are already some utility classes in the event display that handle (in an attempted "smart" way) uncompressed data, and we may consider to promote them, or to write something better.



Also available in: Atom PDF