mirror of https://bitbucket.org/ausocean/av.git
adpcm: length check before initialization
This commit is contained in:
parent
d06388cfe9
commit
ef9a38cb76
|
@ -259,8 +259,13 @@ func (e *encoder) init(samps []byte) {
|
||||||
// It writes its output to the encoder's dest.
|
// It writes its output to the encoder's dest.
|
||||||
// The number of bytes written out is returned along with any error that occured.
|
// The number of bytes written out is returned along with any error that occured.
|
||||||
func (e *encoder) Write(inPcm []byte) (int, error) {
|
func (e *encoder) Write(inPcm []byte) (int, error) {
|
||||||
// Determine if there will be a byte that won't contain two full nibbles and will need padding.
|
// Check that pcm has enough data to initialize decoder
|
||||||
pcmLen := len(inPcm)
|
pcmLen := len(inPcm)
|
||||||
|
if pcmLen < 4 {
|
||||||
|
return 0, fmt.Errorf("length of given byte array must be greater than 4")
|
||||||
|
}
|
||||||
|
|
||||||
|
// Determine if there will be a byte that won't contain two full nibbles and will need padding.
|
||||||
pad := false
|
pad := false
|
||||||
if (pcmLen-2)%4 != 0 {
|
if (pcmLen-2)%4 != 0 {
|
||||||
pad = true
|
pad = true
|
||||||
|
|
Loading…
Reference in New Issue