diff options
-rw-r--r-- | lib/system.nim | 3 | ||||
-rw-r--r-- | lib/system/sysio.nim | 2 |
2 files changed, 5 insertions, 0 deletions
diff --git a/lib/system.nim b/lib/system.nim index 56210f5dc..53204306d 100644 --- a/lib/system.nim +++ b/lib/system.nim @@ -2774,6 +2774,9 @@ when not defined(JS): #and not defined(nimscript): ## reads `len` bytes into the buffer `a` starting at ``a[start]``. Returns ## the actual number of bytes that have been read which may be less than ## `len` (if not as many bytes are remaining), but not greater. + ## + ## **Warning:** The buffer `a` must be pre-allocated. This can be done + ## using, for example, ``newString``. proc readBuffer*(f: File, buffer: pointer, len: Natural): int {. tags: [ReadIOEffect], benign.} diff --git a/lib/system/sysio.nim b/lib/system/sysio.nim index d0bba6775..3c34215ac 100644 --- a/lib/system/sysio.nim +++ b/lib/system/sysio.nim @@ -58,6 +58,8 @@ proc readBytes(f: File, a: var openArray[int8|uint8], start, len: Natural): int result = readBuffer(f, addr(a[start]), len) proc readChars(f: File, a: var openArray[char], start, len: Natural): int = + if (start + len) > len(a): + raiseEIO("buffer overflow: (start+len) > length of openarray buffer") result = readBuffer(f, addr(a[start]), len) proc write(f: File, c: cstring) = fputs(c, f) |