Skip to content

Commit 1498e8b

Browse files
committed
Revert most of commit 4aca6a6 (several files were committed by error)
1 parent baec346 commit 1498e8b

6 files changed

Lines changed: 72 additions & 392 deletions

File tree

src/io/CompressedInputStream.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ using namespace std;
2626

2727

2828
const int CompressedInputStream::BITSTREAM_TYPE = 0x4B414E5A; // "KANZ"
29-
const int CompressedInputStream::BITSTREAM_FORMAT_VERSION = 7;
29+
const int CompressedInputStream::BITSTREAM_FORMAT_VERSION = 6;
3030
const int CompressedInputStream::DEFAULT_BUFFER_SIZE = 256 * 1024;
3131
const int CompressedInputStream::EXTRA_BUFFER_SIZE = 512;
3232
const kanzi::byte CompressedInputStream::COPY_BLOCK_MASK = kanzi::byte(0x80);

src/io/CompressedOutputStream.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ using namespace kanzi;
2929
using namespace std;
3030

3131
const int CompressedOutputStream::BITSTREAM_TYPE = 0x4B414E5A; // "KANZ"
32-
const int CompressedOutputStream::BITSTREAM_FORMAT_VERSION = 7;
32+
const int CompressedOutputStream::BITSTREAM_FORMAT_VERSION = 6;
3333
const int CompressedOutputStream::DEFAULT_BUFFER_SIZE = 256 * 1024;
3434
const kanzi::byte CompressedOutputStream::COPY_BLOCK_MASK = kanzi::byte(0x80);
3535
const kanzi::byte CompressedOutputStream::TRANSFORMS_MASK = kanzi::byte(0x10);

src/test/TestMalformedStream.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ int main()
196196
}
197197

198198
if (expectHeaderFailure("unsupported version",
199-
buildHeader(type, version + 2, 0, entropy, transform, blockSize, 0, 0, true),
199+
buildHeader(type, version + 1, 0, entropy, transform, blockSize, 0, 0, true),
200200
Error::ERR_STREAM_VERSION, "cannot read this version") != 0) {
201201
return 1;
202202
}

src/test/TestTransforms.cpp

Lines changed: 20 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ limitations under the License.
3737
using namespace std;
3838
using namespace kanzi;
3939

40-
static const int BS_VERSION = 7;
40+
static const int BS_VERSION = 6;
4141

4242
static void writeInt16LE(kanzi::byte buf[], int value)
4343
{
@@ -632,73 +632,40 @@ static int testTransformCapacityValidation()
632632
{
633633
LZXCodec<false> tf;
634634
kanzi::byte lzSrc[128];
635-
kanzi::byte lzDst[256];
635+
kanzi::byte lzEncoded[256];
636+
kanzi::byte lzDecoded[128];
636637

637638
for (int i = 0; i < 128; i++)
638-
lzSrc[i] = kanzi::byte(i);
639-
640-
SliceArray<kanzi::byte> input(lzSrc, 128, 1);
641-
SliceArray<kanzi::byte> output(lzDst, 256, 0);
642-
const int savedIIdx = input._index;
643-
const int savedOIdx = output._index;
639+
lzSrc[i] = kanzi::byte(i & 3);
644640

645-
if (tf.forward(input, output, 128) != false) {
646-
cout << "LZX forward should reject oversized remaining input count" << endl;
647-
return 1;
648-
}
641+
memset(lzEncoded, 0, sizeof(lzEncoded));
642+
memset(lzDecoded, 0x7E, sizeof(lzDecoded));
643+
SliceArray<kanzi::byte> input(lzSrc, 128, 0);
644+
SliceArray<kanzi::byte> encoded(lzEncoded, int(sizeof(lzEncoded)), 0);
649645

650-
if ((input._index != savedIIdx) || (output._index != savedOIdx)) {
651-
cout << "LZX forward input capacity failure moved indexes" << endl;
646+
if (tf.forward(input, encoded, 128) == false) {
647+
cout << "LZX setup encoding failed" << endl;
652648
return 1;
653649
}
654-
}
655650

656-
{
657-
LZXCodec<false> tf;
658-
kanzi::byte lzSrc[128];
659-
kanzi::byte lzDst[176];
660-
661-
for (int i = 0; i < 128; i++)
662-
lzSrc[i] = kanzi::byte(i);
663-
664-
memset(lzDst, 0x7E, sizeof(lzDst));
665-
SliceArray<kanzi::byte> input(lzSrc, 128, 0);
666-
SliceArray<kanzi::byte> output(lzDst, int(sizeof(lzDst)), 32);
651+
const int encodedSize = encoded._index;
652+
SliceArray<kanzi::byte> exactInput(lzEncoded, encodedSize, 0);
653+
SliceArray<kanzi::byte> output(lzDecoded, 128, 0);
667654

668-
if (tf.forward(input, output, 128) != false) {
669-
cout << "LZX forward should reject incompressible input" << endl;
655+
if (tf.inverse(exactInput, output, encodedSize) != false) {
656+
cout << "LZX should reject input without the read-length guard" << endl;
670657
return 1;
671658
}
672659

673-
if ((output._index != 32) || (lzDst[32] != kanzi::byte(0x7E))) {
674-
cout << "LZX final-size check wrote output on failure" << endl;
660+
if ((exactInput._index != 0) || (output._index != 0)) {
661+
cout << "LZX guard failure moved slice indexes" << endl;
675662
return 1;
676663
}
677-
}
678664

679-
{
680-
Context v7ctx;
681-
v7ctx.putInt("bsVersion", 7);
682-
LZXCodec<false> encoder(v7ctx);
683-
LZXCodec<false> decoder(v7ctx);
684-
kanzi::byte lzSrc[256];
685-
vector<kanzi::byte> lzEncoded(encoder.getMaxEncodedLength(256));
686-
kanzi::byte lzDecoded[512];
687-
688-
for (int i = 0; i < 256; i++)
689-
lzSrc[i] = kanzi::byte(i & 3);
690-
691-
SliceArray<kanzi::byte> input(lzSrc, 256, 0);
692-
SliceArray<kanzi::byte> encoded(&lzEncoded[0], int(lzEncoded.size()), 0);
693-
SliceArray<kanzi::byte> output(lzDecoded, 512, 0);
694-
695-
const bool encodedOk = encoder.forward(input, encoded, 256);
696-
const int encodedSize = encoded._index;
697-
SliceArray<kanzi::byte> encodedInput(&lzEncoded[0], encodedSize, 0);
698-
const bool decodedOk = decoder.inverse(encodedInput, output, encodedSize);
665+
SliceArray<kanzi::byte> paddedInput(lzEncoded, int(sizeof(lzEncoded)), 0);
699666

700-
if (!encodedOk || !decodedOk || (output._index != 256) || (memcmp(lzSrc, lzDecoded, 256) != 0)) {
701-
cout << "LZX v7 round trip failed" << endl;
667+
if (tf.inverse(paddedInput, output, encodedSize) == false) {
668+
cout << "LZX should accept input with the read-length guard" << endl;
702669
return 1;
703670
}
704671
}

0 commit comments

Comments
 (0)