For a standard BMP, each individual scan line needs to be a multiple of 4 bytes, so when you have a 24 bit image (3 bytes per pixel), you often need to allow for padding at the end of every scan line to bring it up to a multiple of 4.
For example, if your width if 150 pixels, that's 450 bytes, which needs to be rounded up to 452 to make it a multiple of 4.
I suspect that might be the problem you're having here.