Procházet zdrojové kódy

fix: prevent index out of range panic on 32-bit platforms

On 32-bit architectures (e.g. ARM7), int is 32 bits wide.
Casting a uint32 hash value to int can overflow, producing a
negative number. Go's modulo operator preserves the sign, so
the channel index can become -1, causing a panic.

Perform the modulo in uint32 space before indexing to ensure
the result is always non-negative.

Fixes #413
tags/v2.2.5^2^2
Alexey Dolotov před 1 měsícem
rodič
revize
01402bdba2
1 změnil soubory, kde provedl 1 přidání a 1 odebrání
  1. 1
    1
      events/event_stream.go

+ 1
- 1
events/event_stream.go Zobrazit soubor

@@ -38,7 +38,7 @@ func (e EventStream) Send(ctx context.Context, evt mtglib.Event) {
38 38
 	select {
39 39
 	case <-ctx.Done():
40 40
 	case <-e.ctx.Done():
41
-	case e.chans[int(chanNo)%len(e.chans)] <- evt:
41
+	case e.chans[chanNo%uint32(len(e.chans))] <- evt:
42 42
 	}
43 43
 }
44 44
 

Načítá se…
Zrušit
Uložit