add safe guard against an invalid buffer when downloading files