Skip to content
Snippets Groups Projects
Commit 7a350dd1 authored by Vojtech Moravec's avatar Vojtech Moravec
Browse files

Fix QVC header validation and output better error message.

parent f55cdca6
No related branches found
No related tags found
No related merge requests found
......@@ -317,7 +317,7 @@ public class QuantizationCacheManager {
return;
}
if (!qvcFile.getHeader().validateHeader()) {
System.err.println("Provided file is corrupted.");
System.err.println("Provided file is corrupted. Header is not valid.");
return;
}
final StringBuilder reportBuilder = new StringBuilder();
......
package cz.it4i.qcmp.fileformat;
import cz.it4i.qcmp.U16;
import cz.it4i.qcmp.data.V2i;
import cz.it4i.qcmp.data.V3i;
import cz.it4i.qcmp.io.RawDataIO;
......@@ -17,7 +18,6 @@ public class QvcHeaderV1 implements IQvcHeader {
//endregion
//region Header fields.
protected String magicValue;
protected QuantizationType quantizationType;
protected int codebookSize;
protected int trainFileNameSize;
......@@ -40,7 +40,19 @@ public class QvcHeaderV1 implements IQvcHeader {
@Override
public boolean validateHeader() {
return (magicValue != null && magicValue.equals(MAGIC_VALUE));
if (!quantizationType.isOneOf(QuantizationType.Scalar,
QuantizationType.Vector1D,
QuantizationType.Vector2D,
QuantizationType.Vector3D))
return false;
if (!U16.isInRange(codebookSize))
return false;
if (!U16.isInRange(trainFileNameSize) || trainFileName.length() != trainFileNameSize)
return false;
return U16.isInRange(vectorSizeX) && U16.isInRange(vectorSizeY) && U16.isInRange(vectorSizeZ);
}
/**
......
package cz.it4i.qcmp.fileformat;
import cz.it4i.qcmp.U16;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
......@@ -29,7 +31,8 @@ public class QvcHeaderV2 extends QvcHeaderV1 {
@Override
public boolean validateHeader() {
return (magicValue != null && magicValue.equals(MAGIC_VALUE));
final boolean v1HeaderValidation = super.validateHeader();
return U16.isInRange(huffmanDataSize) && v1HeaderValidation;
}
@Override
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment