Support relative strings in metadata

This commit is contained in:
Bertold Van den Bergh 2018-03-11 01:42:08 +01:00
parent 069c4cd546
commit 2ef229ff01

View file

@ -101,8 +101,19 @@ static char* ZDParseString(ZoneDetect* library, uint32_t* index) {
return NULL;
}
if(strLength > 1024) {
return NULL;
uint32_t strOffset = *index;
unsigned int remoteStr = 0;
if(strLength >= 256) {
strOffset = library->metadataOffset + strLength - 256;
remoteStr = 1;
if(!ZDDecodeVariableLengthUnsigned(library, &strOffset, &strLength)) {
return NULL;
}
if(strLength > 256) {
return NULL;
}
}
char* str = malloc(strLength + 1);
@ -110,12 +121,14 @@ static char* ZDParseString(ZoneDetect* library, uint32_t* index) {
if(str) {
unsigned int i;
for(i=0; i<strLength; i++) {
str[i] = library->mapping[*index+i] ^ 0x80;
str[i] = library->mapping[strOffset+i] ^ 0x80;
}
str[strLength] = 0;
}
*index += strLength;
if(!remoteStr) {
*index += strLength;
}
return str;
}