Skip to contentSkip to conversation

erofs-utils: zero directory writer buffer

PATCH In review Garv 2 participants 4 messages Sep 29 Library code

lore
Share & tools
lore

Garv

author
#0 lore raw

PATCH 1/1 erofs-utils: zero directory writer buffer

---
 lib/inode.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
lib/inode.c +1 -1
index ec96556..e7d07e0 100644
@@ -597,7 +597,7 @@ static struct erofs_vfile *erofs_dirwriter_open(struct erofs_inode *dir)
 {
 	struct erofs_dirwriter_vf *dwv;
 
-	dwv = malloc(sizeof(*dwv) + erofs_blksiz(dir->sbi));
+	dwv = calloc(1, sizeof(*dwv) + erofs_blksiz(dir->sbi));
 	if (!dwv)
 		return ERR_PTR(-ENOMEM);
 	dwv->vf.ops = &erofs_dirwriter_vfops;
Signature · 1 line
2.53.0
#1 lore raw
Quoted 1 line · Garv

Can you explain a bit more why we need that?

Thanks,
Gao Xiang

Quoted 21 lines
---
 lib/inode.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
lib/inode.c +1 -1
index ec96556..e7d07e0 100644
@@ -597,7 +597,7 @@ static struct erofs_vfile *erofs_dirwriter_open(struct erofs_inode *dir)
 {
 	struct erofs_dirwriter_vf *dwv;
 
-	dwv = malloc(sizeof(*dwv) + erofs_blksiz(dir->sbi));
+	dwv = calloc(1, sizeof(*dwv) + erofs_blksiz(dir->sbi));
 	if (!dwv)
 		return ERR_PTR(-ENOMEM);
 	dwv->vf.ops = &erofs_dirwriter_vfops;
Signature · 1 line
2.53.0
author
#2 lore raw

Hi Gao,

Thanks for asking. I traced the directory writer path again, and I agree that my original explanation was incomplete. fill_dirblock() already clears the unused portion of the generated directory block, so I shouldn’t have described the change simply as fixing uninitialized directory-block spare space.

The reproducer I used preserves non-zero contents in the output file by bypassing the normal truncation path, and the calloc() change makes the generated image deterministic in that test. However, I have not yet established that dwv->dirdata is the source of those stale bytes, so I don’t want to claim that this is the correct fix without further verification.

I’ll investigate the exact data path and send a revised patch if necessary.

Thanks,
Garv

Quoted 31 lines · Gao Xiang
Quoted 1 line · Garv

Can you explain a bit more why we need that?

Thanks,
Gao Xiang

lib/inode.c static struct erofs_vfile

Quoted 9 lines
---
 lib/inode.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
lib/inode.c +0 -0
index ec96556..e7d07e0 100644
@@ -597,7 +597,7 @@ static struct erofs_vfile

*erofs_dirwriter_open(struct erofs_inode *dir)

Quoted 12 lines
lib/inode.c +1 -2
 {
      struct erofs_dirwriter_vf *dwv;
 
-     dwv = malloc(sizeof(*dwv) + erofs_blksiz(dir->sbi));
+     dwv = calloc(1, sizeof(*dwv) + erofs_blksiz(dir->sbi));
      if (!dwv)
              return ERR_PTR(-ENOMEM);
      dwv->vf.ops = &erofs_dirwriter_vfops;
--

2.53.0

author
#3 lore raw
In reply to Gao Xiang

Hi Gao,

Thanks for asking. I traced the directory writer path again, and I agree that my original explanation was incomplete. fill_dirblock() already clears the unused portion of the generated directory block, so I shouldn’t have described the change simply as fixing uninitialized directory-block spare space.

The reproducer I used preserves non-zero contents in the output file by bypassing the normal truncation path, and the calloc() change makes the generated image deterministic in that test. However, I have not yet established that dwv->dirdata is the source of those stale bytes, so I don’t want to claim that this is the correct fix without further verification.

I’ll investigate the exact data path and send a revised patch if necessary.

Thanks,
Garv

Quoted 31 lines · Gao Xiang
Quoted 1 line · Garv

Can you explain a bit more why we need that?

Thanks,
Gao Xiang

lib/inode.c static struct erofs_vfile

Quoted 9 lines
---
 lib/inode.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
lib/inode.c +0 -0
index ec96556..e7d07e0 100644
@@ -597,7 +597,7 @@ static struct erofs_vfile

*erofs_dirwriter_open(struct erofs_inode *dir)

Quoted 12 lines
lib/inode.c +1 -2
 {
      struct erofs_dirwriter_vf *dwv;
 
-     dwv = malloc(sizeof(*dwv) + erofs_blksiz(dir->sbi));
+     dwv = calloc(1, sizeof(*dwv) + erofs_blksiz(dir->sbi));
      if (!dwv)
              return ERR_PTR(-ENOMEM);
      dwv->vf.ops = &erofs_dirwriter_vfops;
--

2.53.0