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.
Commit
c6265bb3a7eb867d2a960594d2886ce7c65219d416a031be323482b5edf26c43
Parent
7d4af37f39acbdb…
1 file changed
+9
+9
| --- src/unversioned.c | ||
| +++ src/unversioned.c | ||
| @@ -320,10 +320,13 @@ | ||
| 320 | 320 | const char *zError = 0; |
| 321 | 321 | const char *zIn; |
| 322 | 322 | const char *zAs; |
| 323 | 323 | Blob file; |
| 324 | 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. */ | |
| 325 | 328 | |
| 326 | 329 | zAs = find_option("as",0,1); |
| 327 | 330 | verify_all_options(); |
| 328 | 331 | if( zAs && g.argc!=4 ) usage("add DISKFILE --as UVFILE"); |
| 329 | 332 | db_begin_transaction(); |
| @@ -336,13 +339,19 @@ | ||
| 336 | 339 | zError = "be absolute"; |
| 337 | 340 | }else if ( !file_is_simple_pathname(zIn,1) ){ |
| 338 | 341 | zError = "contain complex paths"; |
| 339 | 342 | }else if( contains_whitespace(zIn) ){ |
| 340 | 343 | zError = "contain whitespace"; |
| 344 | + }else if( strlen(zIn)>500 ){ | |
| 345 | + zError = "be more than 500 bytes long"; | |
| 341 | 346 | } |
| 342 | 347 | if( zError ){ |
| 343 | 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); | |
| 344 | 353 | } |
| 345 | 354 | blob_init(&file,0,0); |
| 346 | 355 | blob_read_from_file(&file, g.argv[i], ExtFILE); |
| 347 | 356 | unversioned_write(zIn, &file, mtime); |
| 348 | 357 | blob_reset(&file); |
| 349 | 358 |
| --- 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 |