diff --git a/src/macosx/native/com/sun/media/sound/PLATFORM_API_MacOSX_PCM.cpp b/src/macosx/native/com/sun/media/sound/PLATFORM_API_MacOSX_PCM.cpp index cadbb11bc155825dc0901da6c7d59c241ed56210..608ee13d7ec90be6f42b8229e5cba7b2e6f1e47a 100644 --- a/src/macosx/native/com/sun/media/sound/PLATFORM_API_MacOSX_PCM.cpp +++ b/src/macosx/native/com/sun/media/sound/PLATFORM_API_MacOSX_PCM.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2002, 2015, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2002, 2020, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -202,10 +202,14 @@ public: // (required only if Write() can override the buffer) bool Allocate(int requestedBufferSize, int extraBytes) { int fullBufferSize = requestedBufferSize + extraBytes; - int powerOfTwo = 1; + long powerOfTwo = 1; while (powerOfTwo < fullBufferSize) { powerOfTwo <<= 1; } + if (powerOfTwo > INT_MAX || fullBufferSize < 0) { + ERROR0("RingBuffer::Allocate: REQUESTED MEMORY SIZE IS TOO BIG\n"); + return false; + } pBuffer = (Byte*)malloc(powerOfTwo); if (pBuffer == NULL) { ERROR0("RingBuffer::Allocate: OUT OF MEMORY\n");