Skip to content

add lk console command with PortAudio + WebRTC AEC#775

Closed
theomonnom wants to merge 2 commits intomainfrom
theo/console
Closed

add lk console command with PortAudio + WebRTC AEC#775
theomonnom wants to merge 2 commits intomainfrom
theo/console

Conversation

@theomonnom
Copy link
Copy Markdown
Member

No description provided.

@theomonnom theomonnom force-pushed the theo/console branch 4 times, most recently from cd5d7e2 to 9563002 Compare March 3, 2026 20:35
return fmt.Errorf("ipc: marshal: %w", err)
}

buf := make([]byte, 4+len(data))

Check failure

Code scanning / CodeQL

Size computation for allocation may overflow High

This operation, which is used in an
allocation
, involves a
potentially large value
and might overflow.

Copilot Autofix

AI about 1 hour ago

In general, the fix is to ensure that the size used in the allocation (4 + len(data)) cannot overflow the int type and is within an acceptable bound. This means validating len(data) before performing the addition and before allocating the buffer.

The best way to fix this here, without changing existing functionality, is:

  1. Reuse the existing maxMessageSize bound (1MB) to constrain the size of serialized messages on the write side as well as the read side. This keeps the IPC protocol symmetric: you cannot send larger messages than you are willing to receive.
  2. In WriteProto, after proto.Marshal(msg) succeeds, check len(data):
    • If len(data) > maxMessageSize, return an error like ipc: message too large: %d bytes.
    • This implies 4 + len(data) is at most 4 + maxMessageSize, which is safely within int limits on all supported Go architectures and also below math.MaxUint32, consistent with the 4‑byte length prefix.
  3. Because the bound is small (1MB), we do not need additional explicit overflow arithmetic guards; the inequality check is sufficient to guarantee that 4 + len(data) cannot overflow.

Concretely, in pkg/ipc/ipc.go, in WriteProto between lines 17–22, insert a size check on len(data) before computing buf := make([]byte, 4+len(data)). No new imports or helper functions are required.

Suggested changeset 1
pkg/ipc/ipc.go

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/pkg/ipc/ipc.go b/pkg/ipc/ipc.go
--- a/pkg/ipc/ipc.go
+++ b/pkg/ipc/ipc.go
@@ -18,6 +18,9 @@
 	if err != nil {
 		return fmt.Errorf("ipc: marshal: %w", err)
 	}
+	if len(data) > maxMessageSize {
+		return fmt.Errorf("ipc: message too large: %d bytes", len(data))
+	}
 
 	buf := make([]byte, 4+len(data))
 	binary.BigEndian.PutUint32(buf[:4], uint32(len(data)))
EOF
@@ -18,6 +18,9 @@
if err != nil {
return fmt.Errorf("ipc: marshal: %w", err)
}
if len(data) > maxMessageSize {
return fmt.Errorf("ipc: message too large: %d bytes", len(data))
}

buf := make([]byte, 4+len(data))
binary.BigEndian.PutUint32(buf[:4], uint32(len(data)))
Copilot is powered by AI and may make mistakes. Always verify output.
@theomonnom theomonnom closed this Apr 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants