message: nydus-image: bug fix for `dirents_offset` overflow for non-dir/non-symlink file
  Only the dir and symlink file of rafsv6 can be of EROFS_INODE_FLAT_INLINE layout,
  so we only need to compute dirents offset for these two type of files.
  Otherwise, it may overflow.
diff: @@ -562,13 +562,21 @@ impl Node {
  // update all the inodes's offset according to the new 'meta_addr'.
  self.offset = self.offset - orig_meta_addr + meta_addr;
  + // Only dir and symlink file can be of EROFS_INODE_FLAT_INLINE layout,
  + // so the `dirents_offset` is only used for these two types.
  + // For other types, the `dirents_offset` will always be 0,
  + // To avoid overflow, we add this check.
  + if self.is_dir() || self.is_symlink() {
  self.dirents_offset = self.dirents_offset + meta_addr - orig_meta_addr;
  + }
  +
  if self.is_dir() {
  // the 1st 4k block after dir inode.
  let mut dirent_off = self.dirents_offset;
  inode.set_u((dirent_off / EROFS_BLOCK_SIZE) as u32);
  // Dump inode
  + trace!("{:?} dir inode: offset {}", self.target, self.offset);
  f_bootstrap
  .seek(SeekFrom::Start(self.offset))
  .context("failed seek for dir inode")?;
  @@ -589,14 +597,14 @@ impl Node {
  let mut used: u64 = 0;
  let mut dirents: Vec<(RafsV6Dirent, &OsString)> = Vec::new();
  - trace!("self.dirents.len {}", self.dirents.len());
  + trace!("{:?} self.dirents.len {}", self.target, self.dirents.len());
  // fill dir blocks one by one
  for (offset, name, file_type) in self.dirents.iter() {
  let len = name.len() + size_of::<RafsV6Dirent>();
  if used + len as u64 > EROFS_BLOCK_SIZE {
  // write to bootstrap
  for (entry, name) in dirents.iter_mut() {
  - trace!("nameoff {}", nameoff);
  + trace!("{:?} nameoff {}", name, nameoff);
  entry.set_name_offset(nameoff as u16);
  dir_data.extend(entry.as_ref());
  entry_names.push(*name);
  @@ -658,11 +666,16 @@ impl Node {
  // entry_names.clear();
  // }
  - trace!("used {} dir size {}", used, self.inode.size());
  + trace!(
  + "{:?} used {} dir size {}",
  + self.target,
  + used,
  + self.inode.size()
  + );
  // dump tail part if any
  if used > 0 {
  for (entry, name) in dirents.iter_mut() {
  - trace!("tail nameoff {}", nameoff);
  + trace!("{:?} tail nameoff {}", name, nameoff);
  entry.set_name_offset(nameoff as u16);
  dir_data.extend(entry.as_ref());
  entry_names.push(*name);
  @@ -1210,11 +1223,12 @@ impl Node {
  };
  trace!(
  - "{:?} dir offset {} ctx offset {} d_size {} datalayout {}",
  + "{:?} inode offset {} ctx offset {} d_size {} dirents_offset {} datalayout {}",
  self.name(),
  self.offset,
  bootstrap_ctx.offset,
  d_size,
  + self.dirents_offset,
  self.v6_datalayout
  );
  }
  