summaryrefslogtreecommitdiff
path: root/gr-fec/python/fec/qa_fecapi_cc_buffer_overflow.py
blob: 98344b51757709a6d028e8c8b10c8eb46490ee8b (plain)
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
41
42
43
44
45
46
47
48
49
50
#!/usr/bin/env python
#
# Copyright 2020 Free Software Foundation, Inc.
#
# This file is part of GNU Radio
#
# SPDX-License-Identifier: GPL-3.0-or-later
#
#

from gnuradio import gr, gr_unittest
from gnuradio import fec
from gnuradio import blocks, analog

# This test tries to checks for the kind of buffer overflows in the
# FECAPI convolutional decoder that were fixed in #2965


class test_fecapi_cc_buffer_overflow(gr_unittest.TestCase):

    def run_with_frame_len(self, frame_len):
        self.tb = gr.top_block()
        noise = analog.noise_source_f(analog.GR_GAUSSIAN, 1, 0)
        head = blocks.head(gr.sizeof_float, self.n_frames * frame_len)
        tag = blocks.stream_to_tagged_stream(
            gr.sizeof_float, 1, frame_len, "packet_len")
        stream2pdu = blocks.tagged_stream_to_pdu(blocks.float_t, 'packet_len')

        viterbi = fec.cc_decoder.make(
            frame_len // 2, 7, 2, [79, -109], 0, -1, fec.CC_TERMINATED, False)
        cc_decoder = fec.async_decoder(viterbi, False, False, frame_len)

        self.tb.connect(noise, head, tag, stream2pdu)
        self.tb.msg_connect((stream2pdu, 'pdus'), (cc_decoder, 'in'))

        self.tb.run()
        # the test is considered successful if it hasn't segfaulted or aborted

        self.tb = None

    def test_buffer_overflow_00(self):
        self.n_frames = 10

        for frame_len in range(1000, 2000):
            with self.subTest(frame_length=frame_len):
                self.run_with_frame_len(frame_len)


if __name__ == '__main__':
    gr_unittest.run(test_fecapi_cc_buffer_overflow)