core/log: fix log corruption with messages at 29 second deltas

29, or 0x1d is used as a marker to mean the log level and time delta
cannot fit in a single byte, and the time delta will be a varint
following the current byte.

Prior to this commit, 29 second deltas would be written as 0x1d
instead of 0x1d1d, which the parser interpreted as a hint to read the
next byte, causing the parser to become offset by one byte and all
following logs to be potentially corrupt.
This commit is contained in:
outfoxxed 2024-08-10 01:35:52 -07:00
parent 53b8f1ee0b
commit 5f4d7f89db
Signed by: outfoxxed
GPG key ID: 4C88A185FB89301E

View file

@ -469,7 +469,7 @@ bool EncodedLogWriter::write(const LogMessage& message) {
quint8 field = compressedTypeOf(message.type);
auto secondDelta = this->lastMessageTime.secsTo(message.time);
if (secondDelta > 29) {
if (secondDelta >= 29) {
// 0x1d = followed by delta int
// 0x1e = followed by epoch delta int
field |= (secondDelta < 0xffff ? 0x1d : 0x1e) << 3;