@@ -719,10 +719,26 @@ tmp32 = OF_BSWAP32_IF_BE( (uint32_t)[_modificationDate timeIntervalSince1970]); [data addItems: &tmp32 count: sizeof(tmp32)]; } + + for (OFData *extension in _extensions) { + size_t extensionLength = [extension count]; + + if ([extension itemSize] != 1) + @throw [OFInvalidArgumentException exception]; + + if (extensionLength > UINT16_MAX - 2) + @throw [OFOutOfRangeException exception]; + + tmp16 = OF_BSWAP16_IF_BE((uint16_t)extensionLength + 2); + [data addItems: &tmp16 + count: sizeof(tmp16)]; + [data addItems: [extension items] + count: [extension count]]; + } /* Zero-length extension to terminate */ [data increaseCountBy: 2]; headerSize = [data count];