From 84220120e50bcd228d48288cfa0c115207d7df40 Mon Sep 17 00:00:00 2001 From: Greek64 Date: Tue, 1 Feb 2022 13:40:56 +0100 Subject: [PATCH] Add Bound checks in Decoder stage --- src/IDL-VHDL_Ref.txt | 12 +++++++----- src/Tests/Type2_key_holder.vhd | 6 +++++- src/Tests/Type2_reader_interface.vhd | 18 +++++++++++++++--- 3 files changed, 27 insertions(+), 9 deletions(-) diff --git a/src/IDL-VHDL_Ref.txt b/src/IDL-VHDL_Ref.txt index f3ef873..8578802 100644 --- a/src/IDL-VHDL_Ref.txt +++ b/src/IDL-VHDL_Ref.txt @@ -107,8 +107,10 @@ NAME DIRECTION CONNECTED * GET__LENGTH The first decode_stage is similar to a 4-byte primitive decode stage and latches the length of the sequence into the _len_latch. If the length is equal zero, the decode_stage of the next - declared member is taken, instead of the GET_. A special _cnt counter (used to - index the type specific memory) is initialized to 0. + declared member is taken, instead of the GET_. If on the other hand, the length if greater + than the MAX sequence length specified in the type package, the length is set to the value of the + type package. A special _cnt counter (used to index the type specific memory) is initialized to 0. + NOTE: It could be configured, that instead of truncating larger sequences, a decode error is triggered. * GET_ This stage is similar to the respective primitive decode_stage with following valiations: The _cnt is used to set the current _mem_addr. On sucessful latch @@ -118,11 +120,11 @@ NAME DIRECTION CONNECTED ARRAY ----- -Array is similar to the sequence, but has no length encoding (since it always has the smae size). +Array is similar to the sequence, but has no length encoding (since it always has the same size). That means that there is no _len port signal, _len_latch latch, and also no GET__LENGTH stage. The initialization of the _cnt has to be done in the previous decode_stage. -The _cnt is compared against the fixed array length consatnt form the type package. +The _cnt is compared against the fixed array length constant form the type package. MAP --- @@ -133,7 +135,7 @@ struct _Entry { }; sequence<_Entry> ; -For simplicity the name of the structure is ignored. +For simplicity the name of the _Entry struct is ignored. (I.e. the generated names are _key, _value instead of __Entry_key and __Entry_value) diff --git a/src/Tests/Type2_key_holder.vhd b/src/Tests/Type2_key_holder.vhd index 9a667c4..04f8d95 100644 --- a/src/Tests/Type2_key_holder.vhd +++ b/src/Tests/Type2_key_holder.vhd @@ -339,7 +339,11 @@ begin stage_next <= SKIP_PAYLOAD; else decode_stage_next <= GET_TESTSEQUENCE_TESTARRAY; - TestSequence_len_latch_next <= resize(tmp_length, TestSequence_len_latch_next'length); + if (tmp_length > TESTSEQUENCE_MAX_DEPTH) then + TestSequence_len_latch_next <= to_unsigned(TESTSEQUENCE_MAX_DEPTH, TestSequence_len_latch_next'length); + else + TestSequence_len_latch_next <= resize(tmp_length, TestSequence_len_latch_next'length); + end if; TestSequence_cnt_next <= 0; -- DES: For array types the _cnt has to be initialized in the previous member stage TestSequence_TestArray_cnt_next <= 0; diff --git a/src/Tests/Type2_reader_interface.vhd b/src/Tests/Type2_reader_interface.vhd index 1f2a89d..f5ae34d 100644 --- a/src/Tests/Type2_reader_interface.vhd +++ b/src/Tests/Type2_reader_interface.vhd @@ -684,7 +684,11 @@ begin decode_stage_next <= GET_TESTMAP_LENGTH; else decode_stage_next <= GET_TESTSEQUENCE_TESTARRAY; - TestSequence_len_latch_next <= resize(tmp_length, TestSequence_len_latch_next'length); + if (tmp_length > TESTSEQUENCE_MAX_DEPTH) then + TestSequence_len_latch_next <= to_unsigned(TESTSEQUENCE_MAX_DEPTH, TestSequence_len_latch_next'length); + else + TestSequence_len_latch_next <= resize(tmp_length, TestSequence_len_latch_next'length); + end if; TestSequence_cnt_next <= 0; -- DES: For array types the _cnt has to be initialized in the previous member stage TestSequence_TestArray_cnt_next <= 0; @@ -873,7 +877,11 @@ begin -- Next Member decode_stage_next <= GET_TESTENUM; else - TestMap_len_latch_next <= resize(tmp_length, TestMap_len_latch_next'length); + if (tmp_length > TESTMAP_MAX_DEPTH) then + TestMap_len_latch_next <= to_unsigned(TESTMAP_MAX_DEPTH, TestMap_len_latch_next'length); + else + TestMap_len_latch_next <= resize(tmp_length, TestMap_len_latch_next'length); + end if; TestMap_cnt_next <= 0; decode_stage_next <= GET_TESTMAP_KEY; end if; @@ -1033,7 +1041,11 @@ begin -- DONE stage_next <= SKIP_PAYLOAD; else - TestString_len_latch_next <= resize(tmp_length, TestString_len_latch_next'length); + if (tmp_length > TESTSTRING_MAX_DEPTH) then + TestString_len_latch_next <= to_unsigned(TESTSTRING_MAX_DEPTH, TestString_len_latch_next'length); + else + TestString_len_latch_next <= resize(tmp_length, TestString_len_latch_next'length); + end if; TestString_cnt_next <= 0; decode_stage_next <= GET_TESTSTRING; end if;