Skip to content

runlength optimization works incorrectly in case of changing code paths #13

@neex

Description

@neex

The runlength optimization implicitly relies on the assumption that any particular log message is either never repeated, or always repeated at least twice.

This may not be true when logging depends on some condition:

#include <binary_log/binary_log.hpp>

int main() {
  binary_log::binary_log<> logger("repro.bin");

  for (int i = 0; i < 3; i++) {
    BINARY_LOG(logger, "hui {}", i);
    if (i == 0) {
      BINARY_LOG(logger, "pizda {}", "pidor");
    }
  }

  return 0;
}

In this case, the runlength file will mention that the first message is repeated (which is indeed true for i equal to 1 and 2). However, the unpacker will incorrectly assume the repetition happened at the very first log record (i=0), which results in desync and a segfault during unpacking:

g++ --std=c++20 pizda.cpp -I include -o pizda && ./pizda && ./build/tools/unpacker/unpacker ./repro.bin
hui 0
hui 327681
Segmentation fault (core dumped)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions