diff --git a/src/opus_encoder.c b/src/opus_encoder.c
index 5dda665232360fe54293a8cc00b052e0ec8d44c9..c00bc2f8a159f3c80a83274727df5a30370157bf 100644
--- a/src/opus_encoder.c
+++ b/src/opus_encoder.c
@@ -1212,6 +1212,11 @@ int opus_encode_float(OpusEncoder *st, const opus_val16 *pcm, int frame_size,
        the decoder to call the PLC */
     if (ec_tell(&enc) > (max_data_bytes-1)*8)
     {
+       if (max_data_bytes < 2)
+       {
+          RESTORE_STACK;
+          return OPUS_BUFFER_TOO_SMALL;
+       }
        data[1] = 0;
        ret = 1;
        st->rangeFinal = 0;