RFR: 8336240: Test com/sun/crypto/provider/Cipher/DES/PerformanceTest.java fails with java.lang.ArithmeticException [v5]

Fernando Guallini fguallini at openjdk.org
Thu Jul 25 09:46:48 UTC 2024


> The manual test Cipher/DES/PerformanceTest.java fails with ArithmeticException due to potential division by zero. The issue arises when calculating the elapsed time using end - start, which could result in zero milliseconds if start and end are identical due to the high speed of execution. This leads to a division error in the following code snippet:
> 
> 
> start = System.currentTimeMillis();
> end = System.currentTimeMillis();
> int speed = (int)((data.length * count)/(end - start));
> 
> This issue is easily reproducible on platforms where System.currentTimeMillis() has low granularity, such as many versions of Windows, end and start can be equal when obtaining System.currentTimeMillis() if the test runs very quickly.
> 
> The fix is to use System.nanoTime() instead, which is designed to measure elapsed time with very high precision. This value is then converted to microseconds so the tests can properly calculate the throughput (bytes processed per microsecond) for the report. Example output:
> 
> 
> Algorithm                      DataSize Rounds Bytes/microsec
> DES/ECB/NoPadding               1024    100       66
> DES/ECB/NoPadding               1024    1000      50
> DES/ECB/NoPadding               8192    100       70
> DES/ECB/NoPadding               8192    1000      70
> Average:                                            64

Fernando Guallini has updated the pull request with a new target base due to a merge or a rebase. The incremental webrev excludes the unrelated changes brought in by the merge/rebase. The pull request contains eight additional commits since the last revision:

 - converted to automated test
 - Merge branch 'master' into 8336240
 - adding back the validation to avoid dividing by zero
 - byter per microsec
 - use microseconds as time unit
 - remove unused imports
 - tiny refactor
 - avoid dividing by zero

-------------

Changes:
  - all: https://git.openjdk.org/jdk/pull/20135/files
  - new: https://git.openjdk.org/jdk/pull/20135/files/22ca20b9..98a91557

Webrevs:
 - full: https://webrevs.openjdk.org/?repo=jdk&pr=20135&range=04
 - incr: https://webrevs.openjdk.org/?repo=jdk&pr=20135&range=03-04

  Stats: 11760 lines in 507 files changed: 7377 ins; 2411 del; 1972 mod
  Patch: https://git.openjdk.org/jdk/pull/20135.diff
  Fetch: git fetch https://git.openjdk.org/jdk.git pull/20135/head:pull/20135

PR: https://git.openjdk.org/jdk/pull/20135



More information about the security-dev mailing list