fix(receiver): charge per-entry DirTimeList cost; cap client --skip-compress
This commit is contained in:
@@ -517,6 +517,11 @@ static int parse_skip_compress(Config* config, const char* value) {
|
||||
token[--len] = '\0';
|
||||
if (len == 0)
|
||||
continue;
|
||||
if (config->skip_compress_count >= MAX_SKIP_COMPRESS_SUFFIXES) {
|
||||
fprintf(stderr, "--skip-compress supports at most %d suffixes\n", MAX_SKIP_COMPRESS_SUFFIXES);
|
||||
free(list);
|
||||
return -1;
|
||||
}
|
||||
if (config_add_pattern(&config->skip_compress_suffixes, &config->skip_compress_count, token,
|
||||
"--skip-compress") != 0) {
|
||||
free(list);
|
||||
|
||||
@@ -2274,7 +2274,11 @@ bool dir_time_list_add(DirTimeList* list, const char* wire_path, const FileMetad
|
||||
touching the list, leaving it exactly as it was (the caller fails the
|
||||
transfer, which becomes a clean protocol error). */
|
||||
size_t path_len = strlen(wire_path);
|
||||
if (list->count >= MAX_DIR_TIME_ENTRIES || path_len > MAX_DIR_TIME_BYTES - list->bytes)
|
||||
/* Charge the whole per-entry cost (path copy + pointer slot + metadata
|
||||
struct), not just the path, so the array growth is bounded by the same
|
||||
cumulative budget. */
|
||||
size_t entry_cost = path_len + sizeof(FileMetadata) + sizeof(char*);
|
||||
if (list->count >= MAX_DIR_TIME_ENTRIES || entry_cost > MAX_DIR_TIME_BYTES - list->bytes)
|
||||
return false;
|
||||
if (list->count == list->capacity) {
|
||||
size_t new_capacity = list->capacity == 0 ? 16 : list->capacity * 2;
|
||||
@@ -2302,7 +2306,7 @@ bool dir_time_list_add(DirTimeList* list, const char* wire_path, const FileMetad
|
||||
list->paths[list->count] = copy;
|
||||
list->entries[list->count] = *metadata;
|
||||
list->count++;
|
||||
list->bytes += path_len;
|
||||
list->bytes += entry_cost;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -1396,7 +1396,7 @@ static void test_dir_time_list_cap() {
|
||||
EXPECT_TRUE(list.bytes == before_bytes);
|
||||
} else {
|
||||
EXPECT_TRUE(list.count == before_count + 1);
|
||||
EXPECT_TRUE(list.bytes == before_bytes + path_len);
|
||||
EXPECT_TRUE(list.bytes == before_bytes + path_len + sizeof(FileMetadata) + sizeof(char*));
|
||||
}
|
||||
}
|
||||
EXPECT_TRUE(rejected);
|
||||
|
||||
Reference in New Issue
Block a user