Skip to content

Commit

Permalink
FIX: throw an error when checksum is used with refines on a file ar…
Browse files Browse the repository at this point in the history
…gument
  • Loading branch information
Oldes committed Jun 16, 2023
1 parent 2494ff1 commit 8d4879f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/core/n-strings.c
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ static struct digest {
/*
// checksum: native [
// {Computes a checksum, CRC, hash, or HMAC.}
// data [binary! string! file!] {If string, it will be UTF8 encoded}
// data [binary! string! file!] {If string, it will be UTF8 encoded. File is dispatched to file-checksum function.}
// method [word!] {One of `system/catalog/checksums` and HASH}
// /with {Extra value for HMAC key or hash table size; not compatible with TCP/CRC24/CRC32/ADLER32 methods.}
// spec [any-string! binary! integer!] {String or binary for MD5/SHA* HMAC key, integer for hash table size.}
Expand Down Expand Up @@ -208,6 +208,9 @@ static struct digest {
// Dispatch file to file-checksum function...
REBVAL *func = Find_Word_Value(Lib_Context, SYM_FILE_CHECKSUM);
if (func && IS_FUNCTION(func) && sym > SYM_CRC32 && sym <= SYM_RIPEMD160) {
if (D_REF(ARG_CHECKSUM_WITH) || D_REF(ARG_CHECKSUM_PART))
Trap0(RE_BAD_REFINES);

// Build block to evaluate: [file-checksum data method]
// Where method must be converted to lit-word first...
VAL_TYPE(method) = REB_LIT_WORD;
Expand Down
4 changes: 4 additions & 0 deletions src/tests/units/checksum-test.r3
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,10 @@ AF45D2E376484031617F78D2B58A6B1B9C7EF464F5A01B47E42EC3736322445E
--assert (checksum %units/files/pdf-maker-doc.pdf 'sha1) == #{A598B252C045ABF94EE5F034798B384056C57086}
--assert (checksum %units/files/pdf-maker-doc.pdf 'sha256) == #{FA24645FE45C06DEB31DEC0B4478718A3ABE3F8C923A3B720B5564DAA2C9FC0F}

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


Expand Down

0 comments on commit 8d4879f

Please sign in to comment.