Fossil SCM

Raise an error when trying to insert an unversioned file if the file size would cause the database row to exceed SQLITE_LIMIT_LENGTH.

drh 2025-08-10 10:28 trunk
Commit c6265bb3a7eb867d2a960594d2886ce7c65219d416a031be323482b5edf26c43
1 file changed +9
--- src/unversioned.c
+++ src/unversioned.c
@@ -320,10 +320,13 @@
320320
const char *zError = 0;
321321
const char *zIn;
322322
const char *zAs;
323323
Blob file;
324324
int i;
325
+ i64 mxSize = sqlite3_limit(g.db,SQLITE_LIMIT_LENGTH,-1) - 850;
326
+ /* Extra space for other fields ------^^^ */
327
+ /* of the UNVESIONED table row. */
325328
326329
zAs = find_option("as",0,1);
327330
verify_all_options();
328331
if( zAs && g.argc!=4 ) usage("add DISKFILE --as UVFILE");
329332
db_begin_transaction();
@@ -336,13 +339,19 @@
336339
zError = "be absolute";
337340
}else if ( !file_is_simple_pathname(zIn,1) ){
338341
zError = "contain complex paths";
339342
}else if( contains_whitespace(zIn) ){
340343
zError = "contain whitespace";
344
+ }else if( strlen(zIn)>500 ){
345
+ zError = "be more than 500 bytes long";
341346
}
342347
if( zError ){
343348
fossil_fatal("unversioned filenames may not %s: %Q", zError, zIn);
349
+ }
350
+ if( file_size(g.argv[i], ExtFILE)>mxSize ){
351
+ fossil_fatal("file \"%s\" is too big; max size: %,lld bytes",
352
+ g.argv[i], mxSize);
344353
}
345354
blob_init(&file,0,0);
346355
blob_read_from_file(&file, g.argv[i], ExtFILE);
347356
unversioned_write(zIn, &file, mtime);
348357
blob_reset(&file);
349358
--- src/unversioned.c
+++ src/unversioned.c
@@ -320,10 +320,13 @@
320 const char *zError = 0;
321 const char *zIn;
322 const char *zAs;
323 Blob file;
324 int i;
 
 
 
325
326 zAs = find_option("as",0,1);
327 verify_all_options();
328 if( zAs && g.argc!=4 ) usage("add DISKFILE --as UVFILE");
329 db_begin_transaction();
@@ -336,13 +339,19 @@
336 zError = "be absolute";
337 }else if ( !file_is_simple_pathname(zIn,1) ){
338 zError = "contain complex paths";
339 }else if( contains_whitespace(zIn) ){
340 zError = "contain whitespace";
 
 
341 }
342 if( zError ){
343 fossil_fatal("unversioned filenames may not %s: %Q", zError, zIn);
 
 
 
 
344 }
345 blob_init(&file,0,0);
346 blob_read_from_file(&file, g.argv[i], ExtFILE);
347 unversioned_write(zIn, &file, mtime);
348 blob_reset(&file);
349
--- src/unversioned.c
+++ src/unversioned.c
@@ -320,10 +320,13 @@
320 const char *zError = 0;
321 const char *zIn;
322 const char *zAs;
323 Blob file;
324 int i;
325 i64 mxSize = sqlite3_limit(g.db,SQLITE_LIMIT_LENGTH,-1) - 850;
326 /* Extra space for other fields ------^^^ */
327 /* of the UNVESIONED table row. */
328
329 zAs = find_option("as",0,1);
330 verify_all_options();
331 if( zAs && g.argc!=4 ) usage("add DISKFILE --as UVFILE");
332 db_begin_transaction();
@@ -336,13 +339,19 @@
339 zError = "be absolute";
340 }else if ( !file_is_simple_pathname(zIn,1) ){
341 zError = "contain complex paths";
342 }else if( contains_whitespace(zIn) ){
343 zError = "contain whitespace";
344 }else if( strlen(zIn)>500 ){
345 zError = "be more than 500 bytes long";
346 }
347 if( zError ){
348 fossil_fatal("unversioned filenames may not %s: %Q", zError, zIn);
349 }
350 if( file_size(g.argv[i], ExtFILE)>mxSize ){
351 fossil_fatal("file \"%s\" is too big; max size: %,lld bytes",
352 g.argv[i], mxSize);
353 }
354 blob_init(&file,0,0);
355 blob_read_from_file(&file, g.argv[i], ExtFILE);
356 unversioned_write(zIn, &file, mtime);
357 blob_reset(&file);
358

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button