diff options
| author | Max Graey <maxgraey@gmail.com> | 2019-01-22 05:56:35 +0200 |
|---|---|---|
| committer | Ryan Dahl <ry@tinyclouds.org> | 2019-01-21 21:56:35 -0600 |
| commit | 41829f3e2bd0b1c3af8b508dfafb1b5a17fe59b6 (patch) | |
| tree | 1588c7027b85bf9e0f711376036f479d192549b2 /io/util.ts | |
| parent | d710f9427af35363fb7f9b82d09eae5bd8342a63 (diff) | |
fix possible range issues for copyBytes in io/util (denoland/deno_std#146)
Original: https://github.com/denoland/deno_std/commit/2081f03a0748dac0cf0ab7e6e2d7e427841aca22
Diffstat (limited to 'io/util.ts')
| -rw-r--r-- | io/util.ts | 1 |
1 files changed, 1 insertions, 0 deletions
diff --git a/io/util.ts b/io/util.ts index 3266e5018..185732b36 100644 --- a/io/util.ts +++ b/io/util.ts @@ -4,6 +4,7 @@ import { Buffer, Reader } from "deno"; // from `src`. // Returns the number of bytes copied. export function copyBytes(dst: Uint8Array, src: Uint8Array, off = 0): number { + off = Math.max(0, Math.min(off, dst.byteLength)); const r = dst.byteLength - off; if (src.byteLength > r) { src = src.subarray(0, r); |
