Skip to content

Commit 25e9e07

Browse files
committed
Fix #13937: reject rahash2 -R with -B
-R emits sdb writes to a single key (file.<algo>), so when combined with per-block hashing (-B) each block overwrites the same key and loses data. Reject this combination to avoid misleading output. Document the constraint and add an r2r test.
1 parent 4751998 commit 25e9e07

File tree

3 files changed

+19
-0
lines changed

3 files changed

+19
-0
lines changed

libr/main/rahash2.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -678,6 +678,10 @@ R_API int r_main_rahash2(int argc, const char **argv) {
678678
ret (1);
679679
}
680680
}
681+
if (rad == 3 && !ro->incremental) {
682+
R_LOG_ERROR ("Option -R incompatible with -B (per-block hashing)");
683+
ret (1);
684+
}
681685
ro->mode = rad;
682686
if ((st64)ro->from >= 0 && (st64)ro->to < 0) {
683687
ro->to = 0; // end of file

man/rahash2.1

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,12 @@ $ rahash2 -a sha1 -r file | r2 -qni file
7070
.Bd -literal -offset indent
7171
$ rahash2 -a sha1 -R file | r2 -qni file
7272
.Ed
73+
.Pp
74+
.Nm
75+
.Fl R
76+
is incompatible with
77+
.Fl B
78+
(per-block hashing).
7379
.It Fl s Ar string
7480
Hash this string instead of files
7581
.It Fl t Ar to

test/db/tools/rahash2

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,15 @@ bins/elf/analysis/hello-linux-x86_64: k file.sha256=7bdbf25324af1946ec0b16dbf928
8484
EOF
8585
RUN
8686

87+
NAME=rahash2 -R -B rejected
88+
FILE=-
89+
CMDS=!rahash2 -a md5 -R -B bins/elf/analysis/hello-linux-x86_64
90+
EXPECT=
91+
EXPECT_ERR=<<EOF
92+
ERROR: Option -R incompatible with -B (per-block hashing)
93+
EOF
94+
RUN
95+
8796
NAME=rahash2 -h
8897
FILE=-
8998
CMDS=!rahash2~Usage

0 commit comments

Comments
 (0)