Author: rinrab
Date: Sun Mar 15 15:57:42 2026
New Revision: 1932305

Log:
win32 bcrypt: Handle blocks with sizes larger than what fits in ULONG (32 bits
on Windows). Use a similar code as we recently did to APR-backed checksums.

* subversion/libsvn_subr/checksum_bcrypt.c
  (bcrypt_ctx_update): Update declaration so the function requires a char*
   instead of void*. This is needed to make this pointer incrementable by one
   char. Adding a loop that iterates each the data block-by-block with a size
   of what fits into an integer that is then passed into Win32 API call
   (ULONG). The loop all replaces the assertion that was checking that the
   input parameters match the requirements as now the loop makes the updates
   safe.

Modified:
   subversion/trunk/subversion/libsvn_subr/checksum_bcrypt.c

Modified: subversion/trunk/subversion/libsvn_subr/checksum_bcrypt.c
==============================================================================
--- subversion/trunk/subversion/libsvn_subr/checksum_bcrypt.c   Sun Mar 15 
10:06:15 2026        (r1932304)
+++ subversion/trunk/subversion/libsvn_subr/checksum_bcrypt.c   Sun Mar 15 
15:57:42 2026        (r1932305)
@@ -119,18 +119,28 @@ bcrypt_ctx_init(algorithm_state_t *algor
 static svn_error_t *
 bcrypt_ctx_update(algorithm_state_t *algorithm,
                   bcrypt_ctx_t *ctx,
-                  const void *data,
+                  const char *data,
                   apr_size_t len)
 {
-  SVN_ERR_ASSERT(len <= ULONG_MAX);
-
   if (! ctx->handle)
     SVN_ERR(bcrypt_ctx_init(algorithm, ctx));
 
-  SVN_ERR(handle_error(BCryptHashData(ctx->handle,
-                                      (PUCHAR) data,
-                                      (ULONG) len,
-                                      /* dwFlags */ 0)));
+  while (len > 0)
+    {
+      ULONG block;
+
+      if (len < ULONG_MAX)
+        block = (ULONG)len;
+      else
+        block = UINT_MAX;
+
+      SVN_ERR(handle_error(BCryptHashData(ctx->handle,
+                                          (PUCHAR) data, block,
+                                          /* dwFlags */ 0)));
+
+      len -= block;
+      data += block;
+    }
 
   return SVN_NO_ERROR;
 }

Reply via email to