cncf / cncf-fuzzing

✨🔐 CNCF Fuzzers
https://cncf.io/projects
Apache License 2.0
111 stars 41 forks source link

Keycloak: Fix possible mockito gc overhead #447

Closed arthurscchan closed 1 year ago

arthurscchan commented 1 year ago

Trial fix of gc overheaed from solution of inline mock memory leak in Mockito mentioned in https://github.com/mockito/mockito/issues/1532

arthurscchan commented 1 year ago

In original status, we can see that the memory usage is growing.

#2 pulse  ft: 593 exec/s: 0 rss: 1192Mb
  #4 pulse  cov: 595 ft: 603 corp: 2/2b exec/s: 0 rss: 1192Mb
  #8 pulse  cov: 595 ft: 603 corp: 2/2b exec/s: 1 rss: 1192Mb
  #16 pulse  cov: 595 ft: 603 corp: 2/2b exec/s: 2 rss: 1192Mb
  #32 pulse  cov: 595 ft: 603 corp: 2/2b exec/s: 4 rss: 1192Mb
  #64 pulse  cov: 595 ft: 603 corp: 2/2b exec/s: 9 rss: 1192Mb
  #128 pulse  cov: 595 ft: 603 corp: 2/2b exec/s: 16 rss: 1192Mb
  #256 pulse  cov: 595 ft: 603 corp: 2/2b exec/s: 32 rss: 1192Mb
  #512 pulse  cov: 596 ft: 606 corp: 3/68b exec/s: 51 rss: 1192Mb
  #1024 pulse  cov: 598 ft: 608 corp: 4/580b exec/s: 93 rss: 1192Mb
  #2048 pulse  cov: 598 ft: 608 corp: 4/580b exec/s: 146 rss: 1192Mb
  #2348 INITED cov: 598 ft: 608 corp: 4/580b exec/s: 156 rss: 1192Mb
  #4096 pulse  cov: 598 ft: 608 corp: 4/580b lim: 530 exec/s: 204 rss: 1212Mb
  INFO: Instrumented org.keycloak.services.managers.AuthenticationManager$AuthResult (took 2 ms, size +8%)
  #8192 pulse  cov: 598 ft: 608 corp: 4/580b lim: 575 exec/s: 240 rss: 1520Mb
  INFO: Instrumented org.keycloak.jose.jws.JWSHeader (took 5 ms, size +6%)
  INFO: Instrumented org.keycloak.jose.JOSEHeader (took 0 ms, size +0%)
  #16384 pulse  cov: 598 ft: 608 corp: 4/580b lim: 656 exec/s: 287 rss: 1879Mb
   
  == Java Exception: com.code_intelligence.jazzer.api.FuzzerSecurityIssueLow: Out of memory (use '-Xmx1843m' to reproduce)
  | Caused by: java.lang.OutOfMemoryError: GC overhead limit exceeded

The updated version seems to remain steady after cleaning up mock object.

#2      pulse  ft: 837 exec/s: 0 rss: 1467Mb
#2      INITED cov: 837 ft: 837 corp: 1/1b exec/s: 0 rss: 1467Mb
#4      pulse  cov: 837 ft: 837 corp: 1/1b lim: 4 exec/s: 0 rss: 1467Mb
#8      pulse  cov: 837 ft: 839 corp: 1/1b lim: 4 exec/s: 1 rss: 1467Mb
#8      NEW    cov: 837 ft: 839 corp: 2/3b lim: 4 exec/s: 1 rss: 1467Mb L: 2/2 MS: 2 InsertByte-Custom-
#16     pulse  cov: 837 ft: 839 corp: 2/3b lim: 4 exec/s: 2 rss: 1467Mb
#16     REDUCE cov: 837 ft: 839 corp: 2/2b lim: 4 exec/s: 2 rss: 1467Mb L: 1/1 MS: 6 EraseBytes-Custom-ChangeBit-Custom-ShuffleBytes-Custom-
INFO: Instrumented org.keycloak.events.EventStoreProvider (took 0 ms, size +0%)
#17     REDUCE cov: 853 ft: 980 corp: 3/3b lim: 4 exec/s: 2 rss: 1467Mb L: 1/1 MS: 2 ChangeBinInt-Custom-
#20     REDUCE cov: 853 ft: 981 corp: 4/4b lim: 4 exec/s: 3 rss: 1467Mb L: 1/1 MS: 6 ChangeBit-Custom-CopyPart-Custom-CrossOver-Custom-
#32     pulse  cov: 853 ft: 981 corp: 4/4b lim: 4 exec/s: 5 rss: 1467Mb
#64     pulse  cov: 853 ft: 981 corp: 4/4b lim: 4 exec/s: 8 rss: 1467Mb
#74     NEW    cov: 853 ft: 983 corp: 5/6b lim: 4 exec/s: 9 rss: 1467Mb L: 2/2 MS: 8 CopyPart-Custom-EraseBytes-Custom-CopyPart-Custom-ShuffleBytes-Custom-
#87     NEW    cov: 853 ft: 984 corp: 6/8b lim: 4 exec/s: 10 rss: 1467Mb L: 2/2 MS: 6 ChangeByte-Custom-ShuffleBytes-Custom-ChangeByte-Custom-
#128    pulse  cov: 853 ft: 984 corp: 6/8b lim: 4 exec/s: 12 rss: 1467Mb
#256    pulse  cov: 853 ft: 984 corp: 6/8b lim: 4 exec/s: 17 rss: 1467Mb
#349    REDUCE cov: 853 ft: 984 corp: 6/7b lim: 6 exec/s: 18 rss: 1467Mb L: 1/2 MS: 4 ChangeBit-Custom-EraseBytes-Custom-
#512    pulse  cov: 853 ft: 984 corp: 6/7b lim: 6 exec/s: 20 rss: 1467Mb
INFO: Instrumented org.slf4j.Marker (took 0 ms, size +0%)
#1024   pulse  cov: 853 ft: 984 corp: 6/7b lim: 11 exec/s: 22 rss: 1467Mb
#1122   NEW    cov: 853 ft: 985 corp: 7/15b lim: 11 exec/s: 23 rss: 1467Mb L: 8/8 MS: 6 ShuffleBytes-Custom-InsertRepeatedBytes-Custom-InsertByte-Custom-
#2005   REDUCE cov: 853 ft: 985 corp: 7/14b lim: 17 exec/s: 25 rss: 1467Mb L: 1/8 MS: 6 CrossOver-Custom-ChangeBit-Custom-CrossOver-Custom-
#2048   pulse  cov: 853 ft: 985 corp: 7/14b lim: 17 exec/s: 25 rss: 1467Mb
#3191   REDUCE cov: 853 ft: 985 corp: 7/11b lim: 25 exec/s: 27 rss: 1467Mb L: 5/5 MS: 2 EraseBytes-Custom-
#3393   REDUCE cov: 853 ft: 985 corp: 7/10b lim: 25 exec/s: 27 rss: 1467Mb L: 4/4 MS: 4 ChangeByte-Custom-EraseBytes-Custom-
#4096   pulse  cov: 853 ft: 985 corp: 7/10b lim: 29 exec/s: 27 rss: 1467Mb
#4406   REDUCE cov: 853 ft: 985 corp: 7/8b lim: 33 exec/s: 27 rss: 1467Mb L: 2/2 MS: 6 CrossOver-Custom-ChangeByte-Custom-ChangeByte-Custom-
#5143   REDUCE cov: 853 ft: 985 corp: 7/7b lim: 38 exec/s: 27 rss: 1467Mb L: 1/1 MS: 4 ChangeByte-Custom-EraseBytes-Custom-
f#8192  pulse  cov: 853 ft: 985 corp: 7/7b lim: 68 exec/s: 27 rss: 1467Mb
INFO: Instrumented org.keycloak.services.managers.AuthenticationManager$AuthResult (took 2 ms, size +8%)
INFO: Instrumented org.keycloak.jose.jws.JWSHeader (took 4 ms, size +6%)
INFO: Instrumented org.keycloak.jose.JOSEHeader (took 0 ms, size +0%)
#16384  pulse  cov: 853 ft: 985 corp: 7/7b lim: 149 exec/s: 28 rss: 1467Mb
#32768  pulse  cov: 853 ft: 985 corp: 7/7b lim: 309 exec/s: 28 rss: 1467Mb