borsh/
error.rs

1use crate::io::{Error, ErrorKind, Result};
2use core::mem::size_of;
3pub const ERROR_ZST_FORBIDDEN: &str = "Collections of zero-sized types are not allowed due to deny-of-service concerns on deserialization.";
4
5pub(crate) fn check_zst<T>() -> Result<()> {
6    if size_of::<T>() == 0 {
7        return Err(Error::new(ErrorKind::InvalidData, ERROR_ZST_FORBIDDEN));
8    }
9    Ok(())
10}