This is something to be very, very wary of when storing data blobs in SQL Server. If you compare varbinary fields they will match when one field has one or more extra zero bytes at the end, even if they are different lengths. Observe:
Declare @Varbinary1 Varbinary(Max) = 0x0100 Declare @Varbinary2 Varbinary(Max) = 0x01 Select @Varbinary1 As Varbinary1, @Varbinary2 As Varbinary2, Case When @Varbinary1 = @Varbinary2 Then 'Data matched' Else 'Data did not match' End As DataTest, Len(@Varbinary1) As Len1, Len(@Varbinary2) As Len2, Case When Len(@Varbinary1) = Len(@Varbinary2) Then 'Len matched' Else 'Len did not match' End As LenTest
|0x100||0x01||Data matched||2||1||Len did not match|
So you better test for data equality and length, or detect those 0 bytes at the end when doing comparisons.