SQLite Forum

ASAN: int overflow on pPager->aStat[x]

ASAN: int overflow on pPager->aStat[x]

(1) By anonymous on 2023-12-20 01:40:38 [source]

Version: 3e2ec83e0bad02934b2c024d123f1a293c214a4e

An ASAN/UBSAN warning has just been observed:

sqlite3.c:62197:34: runtime error: signed integer overflow: 2147483647 + 1 cannot be represented in type 'int'

static int getPageNormal(
  Pager *pPager,      /* The pager open on the database file */
  Pgno pgno,          /* Page number to fetch */
  DbPage **ppPage,    /* Write a pointer to the page here */
  int flags           /* PAGER_GET_XXX flags */
  if( pPg->pPager && !noContent ){
    /* In this case the pcache already contains an initialized copy of
    ** the page. Return without further ado.  */
    assert( pgno!=PAGER_SJ_PGNO(pPager) );
=>  pPager->aStat[PAGER_STAT_HIT]++;
    return SQLITE_OK;

  } else {

Being statistics only, this looks benign. Still, if something has be int-typed, I would rather prefer it make a jump from INT_MAX to 0 rather than to INT_MIN if it can be helped.