1
0
mirror of https://github.com/sqlite/sqlite.git synced 2025-07-30 19:03:16 +03:00

Fix a bug in the calculation of the table record header size.

Ticket #1163. (CVS 2389)

FossilOrigin-Name: bf82a04ff7c24a38d45721b3fae69d88d6e83149
This commit is contained in:
drh
2005-03-17 03:15:40 +00:00
parent d5d565235b
commit cb9882a753
4 changed files with 60 additions and 11 deletions

View File

@ -1,5 +1,5 @@
C Fix\ssome\smemory\sleaks\sthat\scan\soccur\sif\sa\smemory\sallocation\sfails.\s(CVS\s2388) C Fix\sa\sbug\sin\sthe\scalculation\sof\sthe\stable\srecord\sheader\ssize.\nTicket\s#1163.\s(CVS\s2389)
D 2005-03-16T12:15:21 D 2005-03-17T03:15:40
F Makefile.in 5c00d0037104de2a50ac7647a5f12769795957a3 F Makefile.in 5c00d0037104de2a50ac7647a5f12769795957a3
F Makefile.linux-gcc 06be33b2a9ad4f005a5f42b22c4a19dab3cbb5c7 F Makefile.linux-gcc 06be33b2a9ad4f005a5f42b22c4a19dab3cbb5c7
F README a01693e454a00cc117967e3f9fdab2d4d52e9bc1 F README a01693e454a00cc117967e3f9fdab2d4d52e9bc1
@ -75,7 +75,7 @@ F src/update.c 42823d00865c9fe4f01b3c62647858726345a28e
F src/utf.c bda5eb85039ef16f2d17004c1e18c96e1ab0a80c F src/utf.c bda5eb85039ef16f2d17004c1e18c96e1ab0a80c
F src/util.c a53b6fc6f09093ecba1ce593ca7cb1cb77b3a20b F src/util.c a53b6fc6f09093ecba1ce593ca7cb1cb77b3a20b
F src/vacuum.c 5cf598003191bd91c17a64742bad8e46241698a8 F src/vacuum.c 5cf598003191bd91c17a64742bad8e46241698a8
F src/vdbe.c 1bf34fb915afffd9b865a81770dc8cb99b3a04ac F src/vdbe.c c35e65da4988900724e75b58c55ea04652160976
F src/vdbe.h 7e307333d74e134eff237bb9d45fe764e544ad6a F src/vdbe.h 7e307333d74e134eff237bb9d45fe764e544ad6a
F src/vdbeInt.h e80721cd8ff611789e20743eec43363a9fb5a48e F src/vdbeInt.h e80721cd8ff611789e20743eec43363a9fb5a48e
F src/vdbeapi.c 467caa6e6fb9247528b1c7ab9132ae1b4748e8ac F src/vdbeapi.c 467caa6e6fb9247528b1c7ab9132ae1b4748e8ac
@ -160,6 +160,7 @@ F test/misc1.test ff817d3740458884fea535b44821ec7e84700457
F test/misc2.test fc052267d5178367f955538ae34aae1b2f696a92 F test/misc2.test fc052267d5178367f955538ae34aae1b2f696a92
F test/misc3.test 7bd937e2c62bcc6be71939faf068d506467b1e03 F test/misc3.test 7bd937e2c62bcc6be71939faf068d506467b1e03
F test/misc4.test 98e5fb5544aeac6cbbc529c79d4144b0936c22de F test/misc4.test 98e5fb5544aeac6cbbc529c79d4144b0936c22de
F test/misc5.test 406d3f9523953a028307d076f2eb2687218cb46d
F test/misuse.test 1c7fee3c4c0cb4008717ecccf5c72281fac0008e F test/misuse.test 1c7fee3c4c0cb4008717ecccf5c72281fac0008e
F test/notnull.test 7a08117a71e74b0321aaa937dbeb41a09d6eb1d0 F test/notnull.test 7a08117a71e74b0321aaa937dbeb41a09d6eb1d0
F test/null.test 69c62daf1630bf54c87bbc7ef2e22012e58d6da8 F test/null.test 69c62daf1630bf54c87bbc7ef2e22012e58d6da8
@ -275,7 +276,7 @@ F www/tclsqlite.tcl e73f8f8e5f20e8277619433f7970060ab01088fc
F www/vdbe.tcl 87a31ace769f20d3627a64fa1fade7fed47b90d0 F www/vdbe.tcl 87a31ace769f20d3627a64fa1fade7fed47b90d0
F www/version3.tcl 092a01f5ef430d2c4acc0ae558d74c4bb89638a0 F www/version3.tcl 092a01f5ef430d2c4acc0ae558d74c4bb89638a0
F www/whentouse.tcl 3e522a06ad41992023c80ca29a048ae2331ca5bd F www/whentouse.tcl 3e522a06ad41992023c80ca29a048ae2331ca5bd
P 856e2ec9688affbfe496cf184f460b18408e3dc0 P 9a358fc33d726d0b5782bf65b50f61f2bd096d56
R bdf8d1650bfb73f4118211dfe43d3498 R f2914c667262d46f447af52a58530a0b
U danielk1977 U drh
Z c63eb3de507eaddae37da59fce3b144c Z 18509b0b70ba94284e40bd44da5c7365

View File

@ -1 +1 @@
9a358fc33d726d0b5782bf65b50f61f2bd096d56 bf82a04ff7c24a38d45721b3fae69d88d6e83149

View File

@ -43,7 +43,7 @@
** in this file for details. If in doubt, do not deviate from existing ** in this file for details. If in doubt, do not deviate from existing
** commenting and indentation practices when changing or adding code. ** commenting and indentation practices when changing or adding code.
** **
** $Id: vdbe.c,v 1.457 2005/03/09 12:26:51 danielk1977 Exp $ ** $Id: vdbe.c,v 1.458 2005/03/17 03:15:40 drh Exp $
*/ */
#include "sqliteInt.h" #include "sqliteInt.h"
#include "os.h" #include "os.h"
@ -2008,6 +2008,7 @@ case OP_MakeRecord: {
int nData = 0; /* Number of bytes of data space */ int nData = 0; /* Number of bytes of data space */
int nHdr = 0; /* Number of bytes of header space */ int nHdr = 0; /* Number of bytes of header space */
int nByte = 0; /* Space required for this record */ int nByte = 0; /* Space required for this record */
int nVarint; /* Number of bytes in a varint */
u32 serial_type; /* Type field */ u32 serial_type; /* Type field */
int containsNull = 0; /* True if any of the data fields are NULL */ int containsNull = 0; /* True if any of the data fields are NULL */
char zTemp[NBFS]; /* Space to hold small records */ char zTemp[NBFS]; /* Space to hold small records */
@ -2058,7 +2059,10 @@ case OP_MakeRecord: {
} }
/* Add the initial header varint and total the size */ /* Add the initial header varint and total the size */
nHdr += sqlite3VarintLen(nHdr); nHdr += nVarint = sqlite3VarintLen(nHdr);
if( nVarint<sqlite3VarintLen(nHdr) ){
nHdr++;
}
nByte = nHdr+nData; nByte = nHdr+nData;
/* Allocate space for the new record. */ /* Allocate space for the new record. */
@ -2087,7 +2091,7 @@ case OP_MakeRecord: {
if( addRowid ){ if( addRowid ){
zCsr += sqlite3VdbeSerialPut(zCsr, pRowid); zCsr += sqlite3VdbeSerialPut(zCsr, pRowid);
} }
assert( zCsr==(zNewRecord+nByte) ); assert( zCsr<=(zNewRecord+nByte) );
/* Pop entries off the stack if required. Push the new record on. */ /* Pop entries off the stack if required. Push the new record on. */
if( !leaveOnStack ){ if( !leaveOnStack ){

44
test/misc5.test Normal file
View File

@ -0,0 +1,44 @@
# 2005 Mar 16
#
# The author disclaims copyright to this source code. In place of
# a legal notice, here is a blessing:
#
# May you do good and not evil.
# May you find forgiveness for yourself and forgive others.
# May you share freely, never taking more than you give.
#
#***********************************************************************
# This file implements regression tests for SQLite library.
#
# This file implements tests for miscellanous features that were
# left out of other test files.
#
# $Id: misc5.test,v 1.1 2005/03/17 03:15:40 drh Exp $
set testdir [file dirname $argv0]
source $testdir/tester.tcl
# Build records using the MakeRecord opcode such that the size of the
# header is at the transition point in the size of a varint.
#
# This test causes an assertion failure or a buffer overrun in version
# 3.1.5 and earlier.
#
for {set i 120} {$i<140} {incr i} {
do_test misc5-1.$i {
catchsql {DROP TABLE t1}
set sql1 {CREATE TABLE t1}
set sql2 {INSERT INTO t1 VALUES}
set sep (
for {set j 0} {$j<$i} {incr j} {
append sql1 ${sep}a$j
append sql2 ${sep}$j
set sep ,
}
append sql1 {);}
append sql2 {);}
execsql $sql1$sql2
} {}
}
finish_test