File size: 1,092 Bytes
a706ef6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#include <csignal>
#include <cstdint>
#include <iostream>
#include <unistd.h>
#include <vector>

#include "avro/Reader.hh"
#include "avro/buffer/Buffer.hh"

namespace {

void timeoutHandler(int) {
    static constexpr char message[] =
        "TIMEOUT: legacy Reader did not return after input EOF\n";
    (void)::write(STDOUT_FILENO, message, sizeof(message) - 1);
    _exit(124);
}

} // namespace

int main() {
    // All bytes keep the continuation bit set. BufferReader::read() returns
    // false at EOF, but Reader::readVarInt() ignores the result and keeps the
    // previous 0x81 byte in `val`, making its do/while loop non-terminating.
    const std::vector<uint8_t> trigger(10, 0x81);
    avro::OutputBuffer output;
    output.writeTo(reinterpret_cast<const char *>(trigger.data()),
                   trigger.size());
    avro::Reader reader(output.extractData());

    std::signal(SIGALRM, timeoutHandler);
    alarm(2);

    int64_t value = 0;
    reader.readValue(value);
    alarm(0);
    std::cout << "UNEXPECTED: legacy Reader returned " << value << '\n';
    return 1;
}