# tls.Client: fix out of bounds panic · gitcafe/zig

[View on GitCafe](https://git.cafe/gitcafe/zig/commit/ca752c61c08eaa06458bdc6fa3cc724c09a62f77)

Repository: [gitcafe/zig](https://git.cafe/gitcafe/zig)

Visibility: public

Requested revision: ca752c61c08eaa06458bdc6fa3cc724c09a62f77

Requested commit: ca752c61c08eaa06458bdc6fa3cc724c09a62f77

Commit: ca752c61c08eaa06458bdc6fa3cc724c09a62f77

Tree: c24949196cded72c8aba71800fb95b0702e96560

Author: Igor Anić

Committer: Andrew Kelley

## Message

```
tls.Client: fix out of bounds panic

When calculating how much ciphertext from the stream can fit into
user and internal buffers we should also take into account ciphertext
data which are already in internal buffer.

Fixes: 15226

Tested with
[this](https://github.com/ziglang/zig/issues/15226#issuecomment-2218809140).
Using client with different read buffers until I, hopefully, understood
what is happening.

Not relevant to this fix, but this
[part](https://github.com/ziglang/zig/blob/95d9292a7a09ed883e65510ec054619747315c48/lib/std/crypto/tls/Client.zig#L988-L991)
is still mystery to me. Why we don't use free_size in buf_cap
calculation. Seems like rudiment from previous implementation without iovec.

```

## Parents

- [80d7e260d78400b841f15e3350473650b87931a5](https://git.cafe/gitcafe/zig/commit/80d7e260d78400b841f15e3350473650b87931a5?format=markdown)

[Source at this commit](https://git.cafe/gitcafe/zig/tree/ca752c61c08eaa06458bdc6fa3cc724c09a62f77?format=markdown)
