File tree Expand file tree Collapse file tree 1 file changed +5
-0
lines changed
Expand file tree Collapse file tree 1 file changed +5
-0
lines changed Original file line number Diff line number Diff line change @@ -256,6 +256,8 @@ SZ_PUBLIC void sz_string_unpack( //
256256}
257257
258258SZ_PUBLIC sz_bool_t sz_string_equal (sz_string_t const * a , sz_string_t const * b ) {
259+ // Fast path for self-comparison
260+ if (a == b ) return sz_true_k ;
259261 // Tempting to say that the external.length is bitwise the same even if it includes
260262 // some bytes of the on-stack payload, but we don't at this writing maintain that invariant.
261263 // (An on-stack string includes noise bytes in the high-order bits of external.length. So do this
@@ -394,6 +396,9 @@ SZ_PUBLIC sz_ptr_t sz_string_expand( //
394396 // The user intended to extend the string.
395397 offset = sz_min_of_two (offset , string_length );
396398
399+ // Guard against integer overflow in size calculation.
400+ if (added_length > SZ_SSIZE_MAX - string_length - 1 ) return SZ_NULL_CHAR ;
401+
397402 // If we are lucky, no memory allocations will be needed.
398403 if (string_length + added_length < string_space ) {
399404 sz_move (string_start + offset + added_length , string_start + offset , string_length - offset );
You can’t perform that action at this time.
0 commit comments