From 2ef229ff018843fc6c7283f115029ddcaf37f31a Mon Sep 17 00:00:00 2001 From: Bertold Van den Bergh Date: Sun, 11 Mar 2018 01:42:08 +0100 Subject: [PATCH] Support relative strings in metadata --- library/zonedetect.c | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/library/zonedetect.c b/library/zonedetect.c index a73d354..61602bb 100644 --- a/library/zonedetect.c +++ b/library/zonedetect.c @@ -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; imapping[*index+i] ^ 0x80; + str[i] = library->mapping[strOffset+i] ^ 0x80; } str[strLength] = 0; } - *index += strLength; + if(!remoteStr) { + *index += strLength; + } return str; }