argilo / gr-nrsc5

A GNU Radio implementation of HD Radio (NRSC-5)
GNU General Public License v3.0
129 stars 24 forks source link

Crash on exit #27

Closed gvanem closed 2 years ago

gvanem commented 2 years ago

While running the sample apps/hd_tx_rtl_file.py, I got a crash in the destructor l2_encoder_impl::~l2_encoder_impl(). The pointer rs_enc given to rs_free_char() was completely bogus (a very high value). Hence the crash with this call-stack:

00 gnuradio_fec!free_rs_char(void * p = 0x484054f8)+0xe
01 gnuradio_nrsc5!gr::nrsc5::l2_encoder_impl::{dtor}(void)+0x42
02 gnuradio_nrsc5!gr::nrsc5::l2_encoder_impl::`scalar deleting destructor'(void)+0x45
03 gnuradio_runtime!std::_Ref_count<gr::basic_block>::_Destroy(void)+0xd
04 nrsc5_python!std::_Ref_count_base::_Decref(void)+0x13
05 nrsc5_python!std::_Ptr_base<gr::nrsc5::l2_encoder>::_Decref(void)+0x1e
06 nrsc5_python!std::shared_ptr<gr::nrsc5::l2_encoder>::{dtor}(void)+0x1e
07 nrsc5_python!pybind11::class_<gr::nrsc5::l2_encoder,gr::block,gr::basic_block,std::shared_ptr<gr::nrsc5::l2_encoder> >::dealloc(struct pybind11::detail::value_and_holder * v_h = 0x00befb20)+0x58
...

So after adding some trace of the value of rs_enc in the constructor + destructor, I see they are very different!

In 'l2_encoder_impl::l2_encoder_impl()', rs_enc=0x17FC2550

pagesize :error: no info; setting pagesize = 4096 
buffer_double_mapped :warning: allocate_buffer: tried to allocate 1026 items of size 80. 
Due to alignment requirements   4096 were allocated.  
If this isn't OK, consider padding   your structure to a power-of-two bytes.   On this platform, our 
allocation granularity is 6553 6 bytes.
Press Enter to quit: block_executor :error: sched: <block l2_encoder (4)> is requesting more input data  than we 
can provide.  ninput_items_required = 714499628  max_possible_items_available = 65535  
If this is a filter, consider reducing the number of taps.

In 'l2_encoder_impl::~l2_encoder_impl()', rs_enc=0x484054F8

Some messages above from gnuradio-runtime.dll could give some hint. But I fail to understand those.

How is it possible that rs_enc becomes different? First I thought gnurado-fec.dll was to blame, but this module works fine elsewhere. So perhaps the use of it has some issues with MSVC + pybind here in this project?

argilo commented 2 years ago

I'm not able to reproduce this with gcc on Linux.

The only explanation I could think of for rs_enc being overwritten is that perhaps there is a buffer overflow that causes data to be written past the end of rs_buf. Could you try increasing the size of rs_buf (in l2_encoder_impl.h) from 255 to something like 512 to see whether that prevents the crash?

gvanem commented 2 years ago

False alarm; it was an issue with my build of gnuradio-fec.dll. In my attempt to support rstest.exe built for -DALL_VERSIONS, I did something stupid. But I'll probably raise this FEC issue in the Gnuradio repo.

argilo commented 2 years ago

OK. Thanks for digging into that.

gvanem commented 2 years ago

But the apps/hd_tx_am_soundcard.py generates sound that sound like this: hd_tx_am_soundcard.mp3.txt

(save and remove the .txt extension). I assume the first 4 sec is some preamble and rest sounds like shit. Does this sound normal?

argilo commented 2 years ago

It sounds as expected to me. The I channel (left) contains the analog audio, and the Q channel (right) contains the digital version.

gvanem commented 2 years ago

Ok, good.