Skip to content

Commit

Permalink
Add memory validation function
Browse files Browse the repository at this point in the history
  • Loading branch information
pyropy committed Oct 28, 2024
1 parent 2159c37 commit 94c19d5
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
2 changes: 1 addition & 1 deletion protocols.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ const (
P_PLAINTEXTV2 = 7367777
P_WEBRTC_DIRECT = 280
P_WEBRTC = 281
P_MEMORY = 0x0309 // 777 decimal
P_MEMORY = 777
)

var (
Expand Down
11 changes: 10 additions & 1 deletion transcoders.go
Original file line number Diff line number Diff line change
Expand Up @@ -490,7 +490,7 @@ func validateHTTPPath(b []byte) error {
return nil // We can represent any byte slice when we escape it.
}

var TranscoderMemory = NewTranscoderFromFunctions(memoryStB, memoryBtS, nil)
var TranscoderMemory = NewTranscoderFromFunctions(memoryStB, memoryBtS, memoryValidate)

func memoryStB(s string) ([]byte, error) {
z, err := strconv.ParseUint(s, 10, 64)
Expand All @@ -509,3 +509,12 @@ func memoryBtS(b []byte) (string, error) {
z := binary.BigEndian.Uint64(b)
return strconv.FormatUint(z, 10), nil
}

func memoryValidate(b []byte) error {
// Ensure the byte array is exactly 8 bytes long for a uint64 in big-endian format
if len(b) != 8 {
return errors.New("invalid length: must be exactly 8 bytes")
}

Check warning on line 517 in transcoders.go

View check run for this annotation

Codecov / codecov/patch

transcoders.go#L516-L517

Added lines #L516 - L517 were not covered by tests

return nil
}

0 comments on commit 94c19d5

Please sign in to comment.