Skip to content

Commit 8d4879f

Browse files
committed
FIX: throw an error when checksum is used with refines on a file argument
1 parent 2494ff1 commit 8d4879f

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

src/core/n-strings.c

+4-1
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ static struct digest {
171171
/*
172172
// checksum: native [
173173
// {Computes a checksum, CRC, hash, or HMAC.}
174-
// data [binary! string! file!] {If string, it will be UTF8 encoded}
174+
// data [binary! string! file!] {If string, it will be UTF8 encoded. File is dispatched to file-checksum function.}
175175
// method [word!] {One of `system/catalog/checksums` and HASH}
176176
// /with {Extra value for HMAC key or hash table size; not compatible with TCP/CRC24/CRC32/ADLER32 methods.}
177177
// spec [any-string! binary! integer!] {String or binary for MD5/SHA* HMAC key, integer for hash table size.}
@@ -208,6 +208,9 @@ static struct digest {
208208
// Dispatch file to file-checksum function...
209209
REBVAL *func = Find_Word_Value(Lib_Context, SYM_FILE_CHECKSUM);
210210
if (func && IS_FUNCTION(func) && sym > SYM_CRC32 && sym <= SYM_RIPEMD160) {
211+
if (D_REF(ARG_CHECKSUM_WITH) || D_REF(ARG_CHECKSUM_PART))
212+
Trap0(RE_BAD_REFINES);
213+
211214
// Build block to evaluate: [file-checksum data method]
212215
// Where method must be converted to lit-word first...
213216
VAL_TYPE(method) = REB_LIT_WORD;

src/tests/units/checksum-test.r3

+4
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,10 @@ AF45D2E376484031617F78D2B58A6B1B9C7EF464F5A01B47E42EC3736322445E
273273
--assert (checksum %units/files/pdf-maker-doc.pdf 'sha1) == #{A598B252C045ABF94EE5F034798B384056C57086}
274274
--assert (checksum %units/files/pdf-maker-doc.pdf 'sha256) == #{FA24645FE45C06DEB31DEC0B4478718A3ABE3F8C923A3B720B5564DAA2C9FC0F}
275275

276+
--test-- "checksum file! with refines"
277+
;; refines are not supported
278+
--assert all [error? e: try [checksum/part %units/files/pdf-maker-doc.pdf 'md5 1] e/id = 'bad-refines]
279+
--assert all [error? e: try [checksum/with %units/files/pdf-maker-doc.pdf 'md5 1] e/id = 'bad-refines]
276280
===end-group===
277281

278282

0 commit comments

Comments
 (0)