@@ -532,7 +532,9 @@ public IRubyObject initialize_copy(ThreadContext context, IRubyObject obj) {
532532 from .checkFrozen ();
533533
534534 try {
535- this .algo = (MessageDigest ) from .algo .clone ();
535+ synchronized (from ) {
536+ this .algo = (MessageDigest ) from .algo .clone ();
537+ }
536538 } catch (CloneNotSupportedException e ) {
537539 String name = from .algo .getAlgorithm ();
538540 throw typeError (context , "Could not initialize copy of digest (" + name + ")" );
@@ -541,7 +543,7 @@ public IRubyObject initialize_copy(ThreadContext context, IRubyObject obj) {
541543 }
542544
543545 @ JRubyMethod (name = {"update" , "<<" })
544- public IRubyObject update (IRubyObject obj ) {
546+ public synchronized IRubyObject update (IRubyObject obj ) {
545547 ByteList bytes = obj .convertToString ().getByteList ();
546548 algo .update (bytes .getUnsafeBytes (), bytes .getBegin (), bytes .getRealSize ());
547549 return this ;
@@ -553,7 +555,7 @@ public IRubyObject finish() {
553555 }
554556
555557 @ JRubyMethod ()
556- public IRubyObject finish (ThreadContext context ) {
558+ public synchronized IRubyObject finish (ThreadContext context ) {
557559 IRubyObject digest = RubyString .newStringNoCopy (context .runtime , algo .digest ());
558560 algo .reset ();
559561 return digest ;
@@ -581,13 +583,13 @@ public IRubyObject block_length(ThreadContext context) {
581583 }
582584
583585 @ JRubyMethod ()
584- public IRubyObject reset () {
586+ public synchronized IRubyObject reset () {
585587 algo .reset ();
586588 return this ;
587589 }
588590
589591 @ JRubyMethod ()
590- public IRubyObject bubblebabble (ThreadContext context ) {
592+ public synchronized IRubyObject bubblebabble (ThreadContext context ) {
591593 final byte [] digest = algo .digest ();
592594 return newString (context , BubbleBabble .bubblebabble (digest , 0 , digest .length ));
593595 }
0 commit comments