mirror of
https://github.com/sqlite/sqlite.git
synced 2025-11-09 14:21:03 +03:00
Take care that a corrupt variable-length integer does not cause 32-bit
integer overflow when parsing a record format, nor cause excessively large memory allocations. (CVS 6719) FossilOrigin-Name: 38b20327a80996c7044b88be32161ac4ac0ec3a9
This commit is contained in:
12
src/util.c
12
src/util.c
@@ -14,7 +14,7 @@
|
||||
** This file contains functions for allocating memory, comparing
|
||||
** strings, and stuff like that.
|
||||
**
|
||||
** $Id: util.c,v 1.257 2009/05/31 21:21:41 drh Exp $
|
||||
** $Id: util.c,v 1.258 2009/06/05 14:17:23 drh Exp $
|
||||
*/
|
||||
#include "sqliteInt.h"
|
||||
#include <stdarg.h>
|
||||
@@ -766,6 +766,10 @@ u8 sqlite3GetVarint(const unsigned char *p, u64 *v){
|
||||
/*
|
||||
** Read a 32-bit variable-length integer from memory starting at p[0].
|
||||
** Return the number of bytes read. The value is stored in *v.
|
||||
**
|
||||
** If the varint stored in p[0] is larger than can fit in a 32-bit unsigned
|
||||
** integer, then set *v to 0xffffffff.
|
||||
**
|
||||
** A MACRO version, getVarint32, is provided which inlines the
|
||||
** single-byte case. All code should use the MACRO version as
|
||||
** this function assumes the single-byte case has already been handled.
|
||||
@@ -831,7 +835,11 @@ u8 sqlite3GetVarint32(const unsigned char *p, u32 *v){
|
||||
p -= 2;
|
||||
n = sqlite3GetVarint(p, &v64);
|
||||
assert( n>3 && n<=9 );
|
||||
*v = (u32)v64;
|
||||
if( (v64 & SQLITE_MAX_U32)!=v64 ){
|
||||
*v = 0xffffffff;
|
||||
}else{
|
||||
*v = (u32)v64;
|
||||
}
|
||||
return n;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user