writting to buffer from serial input
A byte can only contain values from 0 to 255 (including). 

So my guess it works for values until 255.

You should use a different type, e.g. unsigned int or unsigned short.

for (unsigned short i = len; i &lt; 250; i++) buffer[i] = '#';     // pad with #


Also, I advise to use a constant or define for the buffer size, now you have 3 values (512, 500 and 250 in the loop, I assume they should be based on the same value).

About the char*: Looking at StreamReadBytesUntil, it seems that the parameter wants a char* instead of a byte* (which is more or less the same), but it's better to cast to show the parameter is of type char* since that is high likely the exact type (but the official Arduino documentation does not show the parameter types sadly).