added panic on invalid buffer size