Fixed a bug in ResourceRef which resulted in incorrect size of output
bytes in very specific cases