Updat GTKwave libraries from upstream

This commit is contained in:
Wilson Snyder 2024-01-21 13:59:54 -05:00
parent e3f3e3399f
commit 1a2c9ca813
4 changed files with 3193 additions and 1272 deletions

View File

@ -34,7 +34,6 @@
* FST_DEBUG : not for production use, only enable for development
* FST_REMOVE_DUPLICATE_VC : glitch removal (has writer performance impact)
* HAVE_LIBPTHREAD -> FST_WRITER_PARALLEL : enables inclusion of parallel writer code
* FST_DO_MISALIGNED_OPS (defined automatically for x86 and some others) : CPU architecture can handle misaligned loads/stores
* _WAVE_HAVE_JUDY : use Judy arrays instead of Jenkins (undefine if LGPL is not acceptable)
*
*/
@ -132,10 +131,6 @@ void **JenkinsIns(void *base_i, const unsigned char *mem, uint32_t length, uint3
#define FST_GZIO_LEN (32768)
#define FST_HDR_FOURPACK_DUO_SIZE (4*1024*1024)
#if defined(__i386__) || defined(__x86_64__) || defined(_AIX) || defined(__aarch64__)
#define FST_DO_MISALIGNED_OPS
#endif
#if defined(__APPLE__) && defined(__MACH__)
#define FST_MACOSX
#include <sys/sysctl.h>
@ -192,6 +187,16 @@ void **JenkinsIns(void *base_i, const unsigned char *mem, uint32_t length, uint3
/* 01234567 */
/*
* report abort messages
*/
static void chk_report_abort(const char *s)
{
fprintf(stderr,"Triggered %s security check, exiting.\n", s);
abort();
}
/*
* prevent old file overwrite when currently being read
*/
@ -367,22 +372,15 @@ return ptr;
/*
* regular and variable-length integer access functions
*/
#ifdef FST_DO_MISALIGNED_OPS
#define fstGetUint32(x) (*(uint32_t *)(x))
#else
static uint32_t fstGetUint32(unsigned char *mem)
{
uint32_t u32;
unsigned char *buf = (unsigned char *)(&u32);
buf[0] = mem[0];
buf[1] = mem[1];
buf[2] = mem[2];
buf[3] = mem[3];
memcpy(buf, mem, sizeof(uint32_t));
return(*(uint32_t *)buf);
}
#endif
static int fstWriterUint64(FILE *handle, uint64_t v)
@ -550,7 +548,8 @@ return(rc);
static uint32_t fstReaderVarint32(FILE *f)
{
unsigned char buf[5];
int chk_len = 5; /* TALOS-2023-1783 */
unsigned char buf[chk_len];
unsigned char *mem = buf;
uint32_t rc = 0;
int ch;
@ -559,7 +558,9 @@ do
{
ch = fgetc(f);
*(mem++) = ch;
} while(ch & 0x80);
} while((ch & 0x80) && (--chk_len));
if(ch & 0x80) chk_report_abort("TALOS-2023-1783");
mem--;
for(;;)
@ -579,7 +580,8 @@ return(rc);
static uint32_t fstReaderVarint32WithSkip(FILE *f, uint32_t *skiplen)
{
unsigned char buf[5];
int chk_len = 5; /* TALOS-2023-1783 */
unsigned char buf[chk_len];
unsigned char *mem = buf;
uint32_t rc = 0;
int ch;
@ -588,7 +590,9 @@ do
{
ch = fgetc(f);
*(mem++) = ch;
} while(ch & 0x80);
} while((ch & 0x80) && (--chk_len));
if(ch & 0x80) chk_report_abort("TALOS-2023-1783");
*skiplen = mem - buf;
mem--;
@ -609,7 +613,8 @@ return(rc);
static uint64_t fstReaderVarint64(FILE *f)
{
unsigned char buf[16];
int chk_len = 16; /* TALOS-2023-1783 */
unsigned char buf[chk_len];
unsigned char *mem = buf;
uint64_t rc = 0;
int ch;
@ -618,9 +623,12 @@ do
{
ch = fgetc(f);
*(mem++) = ch;
} while(ch & 0x80);
} while((ch & 0x80) && (--chk_len));
if(ch & 0x80) chk_report_abort("TALOS-2023-1783");
mem--;
for(;;)
{
rc <<= 7;
@ -851,11 +859,7 @@ unsigned char *pnt = buf;
uint32_t nxt;
uint32_t len;
#ifdef FST_DO_MISALIGNED_OPS
(*(uint32_t *)(pnt)) = (*(uint32_t *)(u));
#else
memcpy(pnt, u, sizeof(uint32_t));
#endif
pnt += 4;
while((nxt = v>>7))
@ -878,11 +882,7 @@ unsigned char *pnt = buf;
uint32_t nxt;
uint32_t len;
#ifdef FST_DO_MISALIGNED_OPS
(*(uint32_t *)(pnt)) = (*(uint32_t *)(u));
#else
memcpy(pnt, u, sizeof(uint32_t));
#endif
pnt += 4;
while((nxt = v>>7))
@ -1542,7 +1542,7 @@ for(i=0;i<xc->maxhandle;i++)
dmem = packmem = (unsigned char *)malloc(packmemlen = (wrlen * 2) + 2);
}
rc = (xc->fourpack) ? LZ4_compress((char *)scratchpnt, (char *)dmem, wrlen) : fastlz_compress(scratchpnt, wrlen, dmem);
rc = (xc->fourpack) ? LZ4_compress_default((char *)scratchpnt, (char *)dmem, wrlen, packmemlen) : fastlz_compress(scratchpnt, wrlen, dmem);
if(rc < destlen)
{
#ifndef FST_DYNAMIC_ALIAS_DISABLE
@ -1838,6 +1838,14 @@ if(xc->parallel_enabled)
xc->xc_parent = xc;
memcpy(xc2, xc, sizeof(struct fstWriterContext));
if(sizeof(size_t) < sizeof(uint64_t))
{
/* TALOS-2023-1777 for 32b overflow */
uint64_t chk_64 = xc->maxhandle * 4 * sizeof(uint32_t);
size_t chk_32 = xc->maxhandle * 4 * sizeof(uint32_t);
if(chk_64 != chk_32) chk_report_abort("TALOS-2023-1777");
}
xc2->valpos_mem = (uint32_t *)malloc(xc->maxhandle * 4 * sizeof(uint32_t));
memcpy(xc2->valpos_mem, xc->valpos_mem, xc->maxhandle * 4 * sizeof(uint32_t));
@ -2101,7 +2109,7 @@ if(xc && !xc->already_in_close && !xc->already_in_flush)
{
fstWriterMmapSanity(hmem = (unsigned char *)fstMmap(NULL, xc->hier_file_len, PROT_READ|PROT_WRITE, MAP_SHARED, fileno(xc->hier_handle), 0), __FILE__, __LINE__, "hmem");
}
packed_len = LZ4_compress((char *)hmem, (char *)mem, xc->hier_file_len);
packed_len = LZ4_compress_default((char *)hmem, (char *)mem, xc->hier_file_len, lz4_maxlen);
fstMunmap(hmem, xc->hier_file_len);
fourpack_duo = (!xc->repack_on_close) && (xc->hier_file_len > FST_HDR_FOURPACK_DUO_SIZE); /* double pack when hierarchy is large */
@ -2114,7 +2122,7 @@ if(xc && !xc->already_in_close && !xc->already_in_flush)
lz4_maxlen_duo = LZ4_compressBound(packed_len);
mem_duo = (unsigned char *)malloc(lz4_maxlen_duo);
packed_len_duo = LZ4_compress((char *)mem, (char *)mem_duo, packed_len);
packed_len_duo = LZ4_compress_default((char *)mem, (char *)mem_duo, packed_len, lz4_maxlen_duo);
fstWriterVarint(xc->handle, packed_len); /* 1st round compressed length */
fstFwrite(mem_duo, packed_len_duo, 1, xc->handle);
@ -3434,7 +3442,7 @@ return(rc);
#ifndef FST_WRITEX_DISABLE
static void fstWritex(struct fstReaderContext *xc, void *v, int len)
static void fstWritex(struct fstReaderContext *xc, void *v, uint32_t len) /* TALOS-2023-1793: change len to unsigned */
{
unsigned char *s = (unsigned char *)v;
@ -5060,6 +5068,7 @@ if(fv)
for(;;)
{
uint32_t *tc_head = NULL;
uint32_t tc_head_items = 0;
traversal_mem_offs = 0;
fstReaderFseeko(xc, xc->f, blkpos, SEEK_SET);
@ -5103,12 +5112,12 @@ for(;;)
}
mem_required_for_traversal = fstReaderUint64(xc->f);
mem_for_traversal = (unsigned char *)malloc(mem_required_for_traversal + 66); /* add in potential fastlz overhead */
mem_required_for_traversal = fstReaderUint64(xc->f) + 66; /* add in potential fastlz overhead */
mem_for_traversal = (unsigned char *)malloc(mem_required_for_traversal);
#ifdef FST_DEBUG
fprintf(stderr, FST_APIMESS "sec: %u seclen: %d begtim: %d endtim: %d\n",
secnum, (int)seclen, (int)beg_tim, (int)end_tim);
fprintf(stderr, FST_APIMESS "mem_required_for_traversal: %d\n", (int)mem_required_for_traversal);
fprintf(stderr, FST_APIMESS "mem_required_for_traversal: %d\n", (int)mem_required_for_traversal-66);
#endif
/* process time block */
{
@ -5158,6 +5167,22 @@ for(;;)
}
free(time_table);
if(sizeof(size_t) < sizeof(uint64_t))
{
/* TALOS-2023-1792 for 32b overflow */
uint64_t chk_64 = tsec_nitems * sizeof(uint64_t);
size_t chk_32 = ((size_t)tsec_nitems) * sizeof(uint64_t);
if(chk_64 != chk_32) chk_report_abort("TALOS-2023-1792");
}
else
{
uint64_t chk_64 = tsec_nitems * sizeof(uint64_t);
if((chk_64/sizeof(uint64_t)) != tsec_nitems)
{
chk_report_abort("TALOS-2023-1792");
}
}
time_table = (uint64_t *)calloc(tsec_nitems, sizeof(uint64_t));
tpnt = ucdata;
tpval = 0;
@ -5169,7 +5194,23 @@ for(;;)
tpnt += skiplen;
}
tc_head = (uint32_t *)calloc(tsec_nitems /* scan-build */ ? tsec_nitems : 1, sizeof(uint32_t));
tc_head_items = tsec_nitems /* scan-build */ ? tsec_nitems : 1;
if(sizeof(size_t) < sizeof(uint64_t))
{
/* TALOS-2023-1792 for 32b overflow */
uint64_t chk_64 = tc_head_items * sizeof(uint32_t);
size_t chk_32 = ((size_t)tc_head_items) * sizeof(uint32_t);
if(chk_64 != chk_32) chk_report_abort("TALOS-2023-1792");
}
else
{
uint64_t chk_64 = tc_head_items * sizeof(uint32_t);
if((chk_64/sizeof(uint32_t)) != tc_head_items)
{
chk_report_abort("TALOS-2023-1792");
}
}
tc_head = (uint32_t *)calloc(tc_head_items, sizeof(uint32_t));
free(ucdata);
}
@ -5273,6 +5314,10 @@ for(;;)
{
if(value_change_callback)
{
if(xc->signal_lens[idx] > xc->longest_signal_value_len)
{
chk_report_abort("TALOS-2023-1797");
}
memcpy(xc->temp_signal_value_buf, mu+sig_offs, xc->signal_lens[idx]);
xc->temp_signal_value_buf[xc->signal_lens[idx]] = 0;
value_change_callback(user_callback_data_pointer, beg_tim, idx+1, xc->temp_signal_value_buf);
@ -5286,6 +5331,10 @@ for(;;)
vcd_id[0] = (xc->signal_typs[idx] != FST_VT_VCD_PORT) ? 'b' : 'p';
fstWritex(xc, vcd_id, 1);
if((sig_offs + xc->signal_lens[idx]) > frame_uclen)
{
chk_report_abort("TALOS-2023-1793");
}
fstWritex(xc,mu+sig_offs, xc->signal_lens[idx]);
vcd_id[0] = ' '; /* collapse 3 writes into one I/O call */
@ -5410,7 +5459,44 @@ for(;;)
free(chain_table_lengths);
vc_maxhandle_largest = vc_maxhandle;
if(!(vc_maxhandle+1))
{
chk_report_abort("TALOS-2023-1798");
}
if(sizeof(size_t) < sizeof(uint64_t))
{
/* TALOS-2023-1798 for 32b overflow */
uint64_t chk_64 = (vc_maxhandle+1) * sizeof(fst_off_t);
size_t chk_32 = ((size_t)(vc_maxhandle+1)) * sizeof(fst_off_t);
if(chk_64 != chk_32) chk_report_abort("TALOS-2023-1798");
}
else
{
uint64_t chk_64 = (vc_maxhandle+1) * sizeof(fst_off_t);
if((chk_64/sizeof(fst_off_t)) != (vc_maxhandle+1))
{
chk_report_abort("TALOS-2023-1798");
}
}
chain_table = (fst_off_t *)calloc((vc_maxhandle+1), sizeof(fst_off_t));
if(sizeof(size_t) < sizeof(uint64_t))
{
/* TALOS-2023-1798 for 32b overflow */
uint64_t chk_64 = (vc_maxhandle+1) * sizeof(uint32_t);
size_t chk_32 = ((size_t)(vc_maxhandle+1)) * sizeof(uint32_t);
if(chk_64 != chk_32) chk_report_abort("TALOS-2023-1798");
}
else
{
uint64_t chk_64 = (vc_maxhandle+1) * sizeof(uint32_t);
if((chk_64/sizeof(uint32_t)) != (vc_maxhandle+1))
{
chk_report_abort("TALOS-2023-1798");
}
}
chain_table_lengths = (uint32_t *)calloc((vc_maxhandle+1), sizeof(uint32_t));
}
@ -5454,6 +5540,11 @@ for(;;)
uint64_t val = fstGetVarint32(pnt, &skiplen);
fstHandle loopcnt = val >> 1;
if((idx+loopcnt-1) > vc_maxhandle) /* TALOS-2023-1789 */
{
chk_report_abort("TALOS-2023-1789");
}
for(i=0;i<loopcnt;i++)
{
chain_table[idx++] = 0;
@ -5487,6 +5578,12 @@ for(;;)
else
{
fstHandle loopcnt = val >> 1;
if((idx+loopcnt-1) > vc_maxhandle) /* TALOS-2023-1789 */
{
chk_report_abort("TALOS-2023-1789");
}
for(i=0;i<loopcnt;i++)
{
chain_table[idx++] = 0;
@ -5547,6 +5644,11 @@ for(;;)
unsigned long destlen = val;
unsigned long sourcelen = chain_table_lengths[i];
if(traversal_mem_offs >= mem_required_for_traversal)
{
chk_report_abort("TALOS-2023-1785");
}
if(mc_mem_len < chain_table_lengths[i])
{
free(mc_mem);
@ -5575,6 +5677,12 @@ for(;;)
{
int destlen = chain_table_lengths[i] - skiplen;
unsigned char *mu = mem_for_traversal + traversal_mem_offs;
if(traversal_mem_offs >= mem_required_for_traversal)
{
chk_report_abort("TALOS-2023-1785");
}
fstFread(mu, destlen, 1, xc->f);
/* data to process is for(j=0;j<destlen;j++) in mu[j] */
headptr[i] = traversal_mem_offs;
@ -5600,6 +5708,11 @@ for(;;)
tdelta = vli >> 1;
}
if(tdelta >= tc_head_items)
{
chk_report_abort("TALOS-2023-1791");
}
scatterptr[i] = tc_head[tdelta];
tc_head[tdelta] = i+1;
}
@ -5698,6 +5811,11 @@ for(;;)
shamt = 2 << (vli & 1);
tdelta = vli >> shamt;
if((tdelta+i) >= tc_head_items)
{
chk_report_abort("TALOS-2023-1791");
}
scatterptr[idx] = tc_head[i+tdelta];
tc_head[i+tdelta] = idx+1;
}
@ -5731,6 +5849,14 @@ for(;;)
vcdid_len = fstVcdIDForFwrite(vcd_id+1, idx+1);
{
if(sizeof(size_t) < sizeof(uint64_t))
{
/* TALOS-2023-1790 for 32b overflow */
uint64_t chk_64 = len*4 + 1;
size_t chk_32 = len*4 + 1;
if(chk_64 != chk_32) chk_report_abort("TALOS-2023-1790");
}
unsigned char *vesc = (unsigned char *)malloc(len*4 + 1);
int vlen = fstUtilityBinToEsc(vesc, vdata, len);
fstWritex(xc, vesc, vlen);
@ -5756,6 +5882,11 @@ for(;;)
vli = fstGetVarint32NoSkip(mem_for_traversal + headptr[idx]);
tdelta = vli >> 1;
if((tdelta+i) >= tc_head_items)
{
chk_report_abort("TALOS-2023-1791");
}
scatterptr[idx] = tc_head[i+tdelta];
tc_head[i+tdelta] = idx+1;
}
@ -5772,6 +5903,11 @@ for(;;)
if(xc->signal_typs[idx] != FST_VT_VCD_REAL)
{
if(len > xc->longest_signal_value_len)
{
chk_report_abort("TALOS-2023-1797");
}
if(!(vli & 1))
{
int byte = 0;
@ -5817,8 +5953,13 @@ for(;;)
if(fv)
{
unsigned char ch_bp = (xc->signal_typs[idx] != FST_VT_VCD_PORT) ? 'b' : 'p';
uint64_t mem_required_for_traversal_chk = vdata - mem_for_traversal + len;
fstWritex(xc, &ch_bp, 1);
if(mem_required_for_traversal_chk > mem_required_for_traversal)
{
chk_report_abort("TALOS-2023-1793");
}
fstWritex(xc, vdata, len);
}
}
@ -5941,6 +6082,11 @@ for(;;)
vli = fstGetVarint32NoSkip(mem_for_traversal + headptr[idx]);
tdelta = vli >> 1;
if((tdelta+i) >= tc_head_items)
{
chk_report_abort("TALOS-2023-1791");
}
scatterptr[idx] = tc_head[i+tdelta];
tc_head[i+tdelta] = idx+1;
}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -29,6 +29,7 @@
// GTKWave configuration
#define HAVE_LIBPTHREAD
#define FST_WRITER_PARALLEL
#define LZ4_DISABLE_DEPRECATE_WARNINGS
// Include the GTKWave implementation directly
#define FST_CONFIG_INCLUDE "fst_config.h"