From f600ae4622f26680ca67d9f76e8476cd8090a6b0 Mon Sep 17 00:00:00 2001 From: oetiker Date: Wed, 29 Jun 2011 15:18:22 +0000 Subject: [PATCH] proper fix for the header size problem and its effects on rrd_resize git-svn-id: svn://svn.oetiker.ch/rrdtool/trunk@2192 a5681a0c-68f1-0310-ab6d-d61299d08faa --- program/src/rrd_format.c | 3 +-- program/src/rrd_resize.c | 9 +++++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/program/src/rrd_format.c b/program/src/rrd_format.c index 501b2676..5200b337 100644 --- a/program/src/rrd_format.c +++ b/program/src/rrd_format.c @@ -125,8 +125,7 @@ off_t rrd_get_header_size( return sizeof(stat_head_t) + \ sizeof(ds_def_t) * rrd->stat_head->ds_cnt + \ sizeof(rra_def_t) * rrd->stat_head->rra_cnt + \ - sizeof(time_t) + \ - sizeof(live_head_t) + \ + ( atoi(rrd->stat_head->version) < 3 ? sizeof(time_t) : sizeof(live_head_t) ) + \ sizeof(pdp_prep_t) * rrd->stat_head->ds_cnt + \ sizeof(cdp_prep_t) * rrd->stat_head->ds_cnt * rrd->stat_head->rra_cnt + \ sizeof(rra_ptr_t) * rrd->stat_head->rra_cnt; diff --git a/program/src/rrd_resize.c b/program/src/rrd_resize.c index 81410251..3613d3f2 100644 --- a/program/src/rrd_resize.c +++ b/program/src/rrd_resize.c @@ -267,9 +267,14 @@ int rrd_resize( /* Move the rest of the CDPs */ while (1) { - if (rrd_read(rrd_file, &buffer, sizeof(rrd_value_t) * 1) <= 0) + ssize_t b_read; + if ((b_read=rrd_read(rrd_file, &buffer, sizeof(rrd_value_t) * 1)) <= 0) break; - rrd_write(rrd_out_file, &buffer, sizeof(rrd_value_t) * 1); + if(rrd_out_file->pos+b_read > rrd_out_file->file_len) { + fprintf(stderr,"WARNING: ignoring last %zu bytes\nWARNING: if you see this message multiple times for a single file you're in trouble\n", b_read); + continue; + } + rrd_write(rrd_out_file, &buffer, b_read); } rrdnew.rra_def[target_rra].row_cnt += modify; rrd_seek(rrd_out_file, -- 2.30.2