emsec / hal

HAL – The Hardware Analyzer
MIT License
624 stars 76 forks source link

Long init strings make hal crash #546

Open kraemv opened 9 months ago

kraemv commented 9 months ago

Hello everyone, HAL can not handle setting too long init strings. When setting an init string of character length 64, hal accepts the string and crashes when selecting the respective gate.

To reproduce this: Open a netlist that contains at least one LUT6_2 element. Get the gate with: gate = netlist.get_gate_by_id(x); Set a long init string with: gate.set_init_data(["1000100110001001100010011000100110001001100010011000100110001001"]) This returns true, so the init string was set. When clicking on the gate, hal crashes. The error message is: [21.12.2023 14:52:41] [python] [info] Python console execute: "gate.set_init_data(["1000100110001001100010011000100110001001100010011000100110001001"])". [21.12.2023 14:52:41] [python] [info] True terminate called after throwing an instance of 'std::out_of_range' what(): stoull

I guess the best fix would be to reject INIT strings that do not meet the expected length of the specified gate. Note that the above could happen when someone tries to set the INIT string in binary representation

joern274 commented 9 months ago

The function above expects a hex string. However, a range check has been added to the code.