From 26514edfef999081b4b2810e3308c5871825071b Mon Sep 17 00:00:00 2001 From: Jonathan Massot Date: Fri, 3 Oct 2025 11:27:50 +0800 Subject: [PATCH 1/3] datetime upperbound unsigned 32bit --- settings/settings.tbs | 30 +++++++++++++++++++++++++++--- tables/tables.tbs | 38 +++++++++++++++++++++++++------------- 2 files changed, 52 insertions(+), 16 deletions(-) diff --git a/settings/settings.tbs b/settings/settings.tbs index cf63853..b9def82 100644 --- a/settings/settings.tbs +++ b/settings/settings.tbs @@ -1396,6 +1396,7 @@ public function stg_sg_internal(byref stg_name_or_num as string,index as byte,by stg_str=mid(stg_str,index*stg_sdr(num).member_size+1,stg_sdr(num).member_size) 'make sure this member has a valid value + dim skip_bounds_check as byte=0 select case stg_sdr(num).stype case EN_STG_TYPE_BYTE: 'byte- convert into value i=asc(stg_str) @@ -1426,17 +1427,20 @@ public function stg_sg_internal(byref stg_name_or_num as string,index as byte,by dim tmp_t as dword=0 strtobin(tmp_t,stg_str,4) stg_value=lstr(tmp_t) + skip_bounds_check=1 goto lb1 case else: 'dot-decimal string- take length stg_value=ddstr(mid(stg_str,2,asc(left(stg_str,1)))) i=asc(left(stg_str,1)) -lb1: if istg_sdr(num).p2 then + lb1: if skip_bounds_check=0 then + if istg_sdr(num).p2 then stg_sg_internal=EN_STG_STATUS_INVALID 'invalid checksum #if STG_DEBUG_PRINT stg_debug_print_error(debug_str,stg_sg_internal) #endif exit function + end if end if end select @@ -1464,6 +1468,7 @@ lb1: if istg_sdr(num).p2 then #endif 'Branch according to the setting type and verify new value + dim skip_bounds_check as byte=0 select case stg_sdr(num).stype case EN_STG_TYPE_BYTE: 'byte- convert into value i=val(stg_value) @@ -1488,20 +1493,39 @@ lb1: if istg_sdr(num).p2 then goto lb2 case EN_STG_TYPE_TIMESTAMP: 'DateTime - dim dt as dword=stg_value + dim dt as dword=0 + dim b1 as byte + dim k as byte + for k=1 to len(stg_value) + b1=asc(mid(stg_value,k,1)) + if b1>=48 and b1<=57 then + dt=dt*10+(b1-48) + else if b1=32 then + 'ignore spaces + else + stg_sg_internal=EN_STG_STATUS_INVALID + #if STG_DEBUG_PRINT + stg_debug_print_error(debug_str,stg_sg_internal) + #endif + exit function + end if + next k bintostr(new_member_str,dt,4) + skip_bounds_check=1 goto lb2 case EN_STG_TYPE_DOTDECIMAL: 'dot-decimal string- take length new_member_str=ddval(stg_value) new_member_str=chr(len(new_member_str))+new_member_str i=len(new_member_str)-1 -lb2: if istg_sdr(num).p2 then + lb2: if skip_bounds_check=0 then + if istg_sdr(num).p2 then stg_sg_internal=EN_STG_STATUS_INVALID 'invalid checksum #if STG_DEBUG_PRINT stg_debug_print_error(debug_str,stg_sg_internal) #endif exit function + end if end if end select diff --git a/tables/tables.tbs b/tables/tables.tbs index 16d75f0..5578f11 100644 --- a/tables/tables.tbs +++ b/tables/tables.tbs @@ -483,9 +483,10 @@ public function tbl_start() as en_tbl_status_codes exit function end if case EN_TBL_FIELD_TIMESTAMP: ' Timestamp - if p1>2147483647 then + dim dword_p1 as dword=p1 + if dword_p1>4294967295 then #if TBL_DEBUG_PRINT - tbl_debugprint("ERROR (table '"+tbl_item.table_name+"'/field '"+field_item.field_name+"'): minimum value (P1 param) can't exceed 2147483647 for datetime type. It is now "+s) + tbl_debugprint("ERROR (table '"+tbl_item.table_name+"'/field '"+field_item.field_name+"'): minimum value (P1 param) can't exceed 4294967295 for datetime type. It is now "+s) #endif tbl_info_index=0 tbl_start=EN_TBL_STATUS_WRONG_DESCRIPTOR @@ -2273,12 +2274,10 @@ public function tbl_field_sg(byref field_name as string,byref field_value as str w3=asc(mid(s,3,1))*256+asc(mid(s,4,1)) d=w2*65536+w3 field_value =lstr(d) - if tbl_field_info(field_index).field_type=EN_TBL_FIELD_TIMESTAMP then - p1=0 - p2=2147483647 + if tbl_field_info(field_index).field_type<>EN_TBL_FIELD_TIMESTAMP then + if lval(field_value)p2 then goto tbl_invalid end if - if lval(field_value)p2 then goto tbl_invalid case EN_TBL_FIELD_TIME,EN_TBL_FIELD_FLOAT: dim tmp_f as float=0 strtobin(tmp_f,s,4) @@ -2332,13 +2331,26 @@ public function tbl_field_sg(byref field_name as string,byref field_value as str s=chr(len(field_value))+field_value+strgen(fld_sz-len(field_value)-1,chr(TBL_NULL)) case EN_TBL_FIELD_DWORD,EN_TBL_FIELD_TIMESTAMP: if tbl_field_info(field_index).field_type=EN_TBL_FIELD_TIMESTAMP then - p1=0 - p2=2147483647 + 'treat as unsigned 32-bit + d=0 + for i=1 to len(field_value) + b1=asc(mid(field_value,i,1)) + if b1>=48 and b1<=57 then + d=d*10+(b1-48) + else if b1=32 then + 'ignore spaces + else + goto tbl_invalid + end if + next i + w2=d/65536 + w3=d mod 65536 + else + if lval(field_value) < p1 then goto tbl_invalid + if lval(field_value) > p2 then goto tbl_invalid + w2=lval(field_value)/65536 + w3=lval(field_value) mod 65536 end if - if lval(field_value) < p1 then goto tbl_invalid - if lval(field_value) > p2 then goto tbl_invalid - w2=lval(field_value)/65536 - w3=lval(field_value) mod 65536 s=chr(w2/256)+chr(w2 mod 256)+chr(w3/256)+chr(w3 mod 256) case EN_TBL_FIELD_FLOAT,EN_TBL_FIELD_TIME: dim tmp_f as float=string_to_float(field_value) From 2f9e173012777b595528eb1f344c8d584410f25d Mon Sep 17 00:00:00 2001 From: Jonathan Massot Date: Tue, 7 Oct 2025 17:26:48 +0800 Subject: [PATCH 2/3] library table field type fix --- tables/tables.tbs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tables/tables.tbs b/tables/tables.tbs index 5578f11..35dd690 100644 --- a/tables/tables.tbs +++ b/tables/tables.tbs @@ -557,7 +557,7 @@ public function tbl_start() as en_tbl_status_codes end select field_item.p2=p2 - if field_item.p2EN_TBL_FIELD_TIMESTRING then + if field_item.p2EN_TBL_FIELD_TIMESTAMP then #if TBL_DEBUG_PRINT tbl_debugprint("ERROR (table '"+tbl_item.table_name+"'/field '"+field_item.field_name+"'): P2 parameter (now "+lstr(field_item.p2)+") cannot be smaller than P1 parameter (now "+lstr(field_item.p1)+").") #endif From 447302ab41943adbedd7a3ba5485f795bc858cf5 Mon Sep 17 00:00:00 2001 From: Jonathan Massot Date: Wed, 8 Oct 2025 16:07:31 +0800 Subject: [PATCH 3/3] table write with timestamp fix --- tables/tables.tbs | 21 +++------------------ 1 file changed, 3 insertions(+), 18 deletions(-) diff --git a/tables/tables.tbs b/tables/tables.tbs index 35dd690..8234859 100644 --- a/tables/tables.tbs +++ b/tables/tables.tbs @@ -2330,27 +2330,12 @@ public function tbl_field_sg(byref field_name as string,byref field_value as str if len(field_value) > p2 then goto tbl_invalid s=chr(len(field_value))+field_value+strgen(fld_sz-len(field_value)-1,chr(TBL_NULL)) case EN_TBL_FIELD_DWORD,EN_TBL_FIELD_TIMESTAMP: - if tbl_field_info(field_index).field_type=EN_TBL_FIELD_TIMESTAMP then - 'treat as unsigned 32-bit - d=0 - for i=1 to len(field_value) - b1=asc(mid(field_value,i,1)) - if b1>=48 and b1<=57 then - d=d*10+(b1-48) - else if b1=32 then - 'ignore spaces - else - goto tbl_invalid - end if - next i - w2=d/65536 - w3=d mod 65536 - else + if tbl_field_info(field_index).field_type<>EN_TBL_FIELD_TIMESTAMP then if lval(field_value) < p1 then goto tbl_invalid if lval(field_value) > p2 then goto tbl_invalid - w2=lval(field_value)/65536 - w3=lval(field_value) mod 65536 end if + w2=lval(field_value)/65536 + w3=lval(field_value) mod 65536 s=chr(w2/256)+chr(w2 mod 256)+chr(w3/256)+chr(w3 mod 256) case EN_TBL_FIELD_FLOAT,EN_TBL_FIELD_TIME: dim tmp_f as float=string_to_float(field_value)