saferio
packagestandard libraryThis package is not in the latest version of its module.
Details
Validgo.mod file
The Go module system was introduced in Go 1.11 and is the official dependency management solution for Go.
Redistributable license
Redistributable licenses place minimal restrictions on how software can be used, modified, and redistributed.
Tagged version
Modules with tagged versions give importers more predictable builds.
Stable version
When a project reaches major version v1 it is considered stable.
- Learn more about best practices
Repository
Links
Documentation¶
Overview¶
Package saferio provides I/O functions that avoid allocating largeamounts of memory unnecessarily. This is intended for packages thatread data from anio.Reader where the size is part of the inputdata but the input may be corrupt, or may be provided by anuntrustworthy attacker.
Index¶
Constants¶
This section is empty.
Variables¶
This section is empty.
Functions¶
funcReadData¶
ReadData reads n bytes from the input stream, but avoids allocatingall n bytes if n is large. This avoids crashing the program byallocating all n bytes in cases where n is incorrect.
The error is io.EOF only if no bytes were read.If an io.EOF happens after reading some but not all the bytes,ReadData returns io.ErrUnexpectedEOF.
funcReadDataAt¶
ReadDataAt reads n bytes from the input stream at off, but avoidsallocating all n bytes if n is large. This avoids crashing the programby allocating all n bytes in cases where n is incorrect.
funcSliceCapWithSize¶added ingo1.22.0
SliceCapWithSize returns the capacity to use when allocating a slice.After the slice is allocated with the capacity, it should bebuilt using append. This will avoid allocating too much memoryif the capacity is large and incorrect.
A negative result means that the value is always too big.
Types¶
This section is empty.