Unexpected dimension mismatch when using read!(io, BitArray)



I am running into a strange DimensionMismatch error when using read! to fill a BitArray. The offending lines look like this:

frames = BitArray(N_bits_per_frame, N_frames)
read!(joinpath(root_dir, bin_file), frames)

The strange thing is, this is part of a loop, and depending on the values of N_bits_per_frame and N_frames the line executes just fine. However, the values below cause an error:

frames = BitArray(480, 89893)
read!(joinpath(root_dir, bin_file), frames)

Julia outputs
ERROR: LoadError: DimensionMismatch("read mismatch, found non-zero bits after BitArray length")
This is especially perplexing because other combinations of N_bits_per_frame and N_frames don’t produce an error. For example:

frames = BitArray(480, 89896)
read!(joinpath(root_dir, bin_file), frames)

runs just fine.

Is this a bug? It seems that read!(s::IO, B::BitArray) operates by filling B's chunks, but then shouldn’t it intelligently truncate to B's initial dimensions? What am I missing here?