BUG: in ioctl(TIOCGWINSZ, winsize *), winsize is 'hhhh'
State: closed

discovered with valgrind when looking for a different problem. See ``man 4 tty_ioctl``.



Labels:
name: Output-Formatting
description: __repr__ of pandas objects, to_string

Comments:
is there a way this affects things? IOW what was broken / now fixed?
The ioctl call writes to a buffer passed in with the function call. Before the fix the call would overwrite the end of the provided buffer of length four bytes, so I made the buffer size fit the definition, now the call does not write to random memory.

Valgrind's memory checker complained when running code that called this function before the commit, and didn't complain after.
this seems to break some of our tests.
# [Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/16125?src=pr&el=h1) Report
> Merging [#16125](https://codecov.io/gh/pandas-dev/pandas/pull/16125?src=pr&el=desc) into [master](https://codecov.io/gh/pandas-dev/pandas/commit/ea56550ded81ff20e6ac77548958231a895264f3?src=pr&el=desc) will **decrease** coverage by `0.01%`.
> The diff coverage is `100%`.

[![Impacted file tree graph](https://codecov.io/gh/pandas-dev/pandas/pull/16125/graphs/tree.svg?src=pr&token=eZ4WkYLtcO&height=150&width=650)](https://codecov.io/gh/pandas-dev/pandas/pull/16125?src=pr&el=tree)

```diff
@@            Coverage Diff             @@
##           master   #16125      +/-   ##
==========================================
- Coverage   90.34%   90.32%   -0.02%     
==========================================
  Files         167      167              
  Lines       50908    50908              
==========================================
- Hits        45994    45984      -10     
- Misses       4914     4924      +10
```

| Flag | Coverage Δ | |
|---|---|---|
| #multiple | `88.11% <100%> (-0.01%)` | :arrow_down: |
| #single | `40.29% <100%> (-0.11%)` | :arrow_down: |

| [Impacted Files](https://codecov.io/gh/pandas-dev/pandas/pull/16125?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [pandas/io/formats/terminal.py](https://codecov.io/gh/pandas-dev/pandas/pull/16125?src=pr&el=tree#diff-cGFuZGFzL2lvL2Zvcm1hdHMvdGVybWluYWwucHk=) | `47.82% <100%> (ø)` | :arrow_up: |
| [pandas/io/gbq.py](https://codecov.io/gh/pandas-dev/pandas/pull/16125?src=pr&el=tree#diff-cGFuZGFzL2lvL2dicS5weQ==) | `25% <0%> (-58.34%)` | :arrow_down: |
| [pandas/core/frame.py](https://codecov.io/gh/pandas-dev/pandas/pull/16125?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvZnJhbWUucHk=) | `97.59% <0%> (-0.1%)` | :arrow_down: |
| [pandas/core/indexes/datetimes.py](https://codecov.io/gh/pandas-dev/pandas/pull/16125?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvaW5kZXhlcy9kYXRldGltZXMucHk=) | `95.23% <0%> (-0.1%)` | :arrow_down: |

------

[Continue to review full report at Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/16125?src=pr&el=continue).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/16125?src=pr&el=footer). Last update [ea56550...eef0ab5](https://codecov.io/gh/pandas-dev/pandas/pull/16125?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).

# [Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/16125?src=pr&el=h1) Report
> Merging [#16125](https://codecov.io/gh/pandas-dev/pandas/pull/16125?src=pr&el=desc) into [master](https://codecov.io/gh/pandas-dev/pandas/commit/ea56550ded81ff20e6ac77548958231a895264f3?src=pr&el=desc) will **decrease** coverage by `0.01%`.
> The diff coverage is `100%`.

[![Impacted file tree graph](https://codecov.io/gh/pandas-dev/pandas/pull/16125/graphs/tree.svg?src=pr&token=eZ4WkYLtcO&height=150&width=650)](https://codecov.io/gh/pandas-dev/pandas/pull/16125?src=pr&el=tree)

```diff
@@            Coverage Diff             @@
##           master   #16125      +/-   ##
==========================================
- Coverage   90.34%   90.32%   -0.02%     
==========================================
  Files         167      167              
  Lines       50908    50908              
==========================================
- Hits        45994    45984      -10     
- Misses       4914     4924      +10
```

| Flag | Coverage Δ | |
|---|---|---|
| #multiple | `88.11% <100%> (-0.01%)` | :arrow_down: |
| #single | `40.29% <100%> (-0.11%)` | :arrow_down: |

| [Impacted Files](https://codecov.io/gh/pandas-dev/pandas/pull/16125?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [pandas/io/formats/terminal.py](https://codecov.io/gh/pandas-dev/pandas/pull/16125?src=pr&el=tree#diff-cGFuZGFzL2lvL2Zvcm1hdHMvdGVybWluYWwucHk=) | `47.82% <100%> (ø)` | :arrow_up: |
| [pandas/io/gbq.py](https://codecov.io/gh/pandas-dev/pandas/pull/16125?src=pr&el=tree#diff-cGFuZGFzL2lvL2dicS5weQ==) | `25% <0%> (-58.34%)` | :arrow_down: |
| [pandas/core/frame.py](https://codecov.io/gh/pandas-dev/pandas/pull/16125?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvZnJhbWUucHk=) | `97.59% <0%> (-0.1%)` | :arrow_down: |
| [pandas/core/indexes/datetimes.py](https://codecov.io/gh/pandas-dev/pandas/pull/16125?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvaW5kZXhlcy9kYXRldGltZXMucHk=) | `95.23% <0%> (-0.1%)` | :arrow_down: |

------

[Continue to review full report at Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/16125?src=pr&el=continue).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/16125?src=pr&el=footer). Last update [ea56550...eef0ab5](https://codecov.io/gh/pandas-dev/pandas/pull/16125?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).

the label for this pull request is Windows, but it actually is about terminal size on Linux. I could not find a place to remove the label in the github interface, maybe I don't have permissions?
ok, what is the actual change here? IOW what bad behavior was there that this fixes?
The original code has a buffer overflow error which is a security issue, and can cause random memory corruption, see for instance http://www.cis.syr.edu/~wedu/Teaching/IntrCompSec/LectureNotes_New/Buffer_Overflow.pdf

It is only four bytes, so probably not too dangerous but should be fixed
can u show something that failed before but works. now?
Valgrind's memory checker complains about the original code writing to memory it does not own. After the patch, valgrind does not conplain. I verified that the complaint is justified by reading the man page for the tty_ioctl syscall, which specifies the size of the input buffer to the syscall
You are correct in asking for proof that there is a problem :). Valgrind actually only complains on PyPy,. In CPython, ``fcntl.ioctl`` allocates its own buffer, copies the input to the internal buffer one, makes the call, and returns the first ``len(buffer)`` bytearray from the internal buffer.

The call in pandas as currently written is misleading but not dangerous.

PyPy only uses the external buffer as provided, so now I will turn to the PyPy group and see how we should deal with this.