google / open-vcdiff

An encoder/decoder for the VCDIFF (RFC3284) format
Apache License 2.0
187 stars 52 forks source link

vcdiff crashes with zero-size dictionary #6

Closed Steelskin closed 10 years ago

Steelskin commented 10 years ago

Original issue 6 created by stas@sl.iae.nsk.su on 2008-09-11T05:57:48.000Z:

What steps will reproduce the problem?

  1. Create empty file empty.dict
  2. Create a non-empty file sample.txt
  3. vcdiff encode --dictionary empty.dict < sample.txt > out.delta

The crash may be platform/STL/configuration-dependent, see the comment below.

What is the expected output? What do you see instead? I expect it to work as if no dictionary was specified, as a compressor, looking for string re-occurences within a single input file; or, if that is not desired behaivior, printing an error message.

Instead it crashes.

Platform: Microsoft Visual Studio 2008 Version 9.0.21022.8 RTM OS Name Microsoft Windows XP Professional
Version 5.1.2600 Service Pack 2 Build 2600

The crash takes place within STL, when empty dictionary is indexed by [0] here: dictionary.resize(dictionarysize); if (fread(&dictionary[0], 1, dictionary_size, dictionary_file) != dictionary_size) {

In Debug configuration, STL debug assertion _DEBUG_ERROR("vector subscript out of range"); is triggered.

Certain STL implementation in some configurations may allow taking an address of a first element of an empty vector, even if this address is technically NULL. If this address is never dereferened (which is a natural assumption since the size is zero), this never leads to a crash; but it is not a safe practice.

STLPort has a similar check is _STLP_DEBUG mode.