fix invalid buffer size causing segfaults