linux-btrfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH V2][BTRFS-PROGS] [BUG] Fix Bug to corrupt the img file
@ 2012-10-25 16:12 Rock Lee
  2012-10-25 16:43 ` [PATCH V2][BTRFS-PROGS] [BUG] Fix Bug to corrupt the img file Reply-To: dave@jikos.cz David Sterba
  0 siblings, 1 reply; 3+ messages in thread
From: Rock Lee @ 2012-10-25 16:12 UTC (permalink / raw)
  To: linux-btrfs

Fix Bug to corrupt the img file

Reproduce steps:
  > dd if=/dev/zero of=btrfs-small.img bs=1M count=1
  > ls -lh btrfs-small.img
  -rw-rw-r--. 1 rock rock 1.0M Oct 24 09:51 btrfs-small.img
                                      ^^^
  > mkfs.btrfs btrfs-small.img
  -rw-rw-r--. 1 rock rock 2.0M Oct 24 09:53 btrfs-small.img
                                      ^^^

Here you can see the original img file's size goes larger to 2Mb.

Signed-off-by: Rock Lee <zimilo@code-trick.com>
---
 utils.c |    6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/utils.c b/utils.c
index 205e667..7ba746e 100644
--- a/utils.c
+++ b/utils.c
@@ -557,6 +557,12 @@ int btrfs_prepare_device(int fd, char *file, int
zero_end, u64 *block_count_ret,
        }
        if (max_block_count)
                block_count = min(block_count, max_block_count);
+
+       if (block_count < 2 * 1024 * 1024) {
+               fprintf(stderr, "size of %s is too small(less than
2Mb)\n", file);
+               exit(1);
+       }
+
        zero_end = 1;

        if (block_count < 1024 * 1024 * 1024 && !(*mixed)) {
-- 
1.7.9.5

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH V2][BTRFS-PROGS] [BUG] Fix Bug to corrupt the img file Reply-To: dave@jikos.cz
  2012-10-25 16:12 [PATCH V2][BTRFS-PROGS] [BUG] Fix Bug to corrupt the img file Rock Lee
@ 2012-10-25 16:43 ` David Sterba
  2012-10-25 23:36   ` Rock Lee
  0 siblings, 1 reply; 3+ messages in thread
From: David Sterba @ 2012-10-25 16:43 UTC (permalink / raw)
  To: Rock Lee; +Cc: linux-btrfs

On Fri, Oct 26, 2012 at 12:12:24AM +0800, Rock Lee wrote:
> Fix Bug to corrupt the img file
> 
> Reproduce steps:
>   > dd if=/dev/zero of=btrfs-small.img bs=1M count=1
>   > ls -lh btrfs-small.img
>   -rw-rw-r--. 1 rock rock 1.0M Oct 24 09:51 btrfs-small.img
>                                       ^^^
>   > mkfs.btrfs btrfs-small.img
>   -rw-rw-r--. 1 rock rock 2.0M Oct 24 09:53 btrfs-small.img
>                                       ^^^
> 
> Here you can see the original img file's size goes larger to 2Mb.

Thanks, fixes this particular bug; although it crashes later at

  mkfs.btrfs: volumes.c:796: btrfs_alloc_chunk: Assertion `!(ret)' failed

but this is a separate issue and you've sent patches for that IIRC.

> --- a/utils.c
> +++ b/utils.c
> @@ -557,6 +557,12 @@ int btrfs_prepare_device(int fd, char *file, int
> zero_end, u64 *block_count_ret,
>         }
>         if (max_block_count)
>                 block_count = min(block_count, max_block_count);
> +
> +       if (block_count < 2 * 1024 * 1024) {
> +               fprintf(stderr, "size of %s is too small(less than
> 2Mb)\n", file);

line wrapped, please check your mailer (easy to fix but additional
unnecessary work)

> +               exit(1);
> +       }
> +

Otherwise ack from me.

david

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH V2][BTRFS-PROGS] [BUG] Fix Bug to corrupt the img file Reply-To: dave@jikos.cz
  2012-10-25 16:43 ` [PATCH V2][BTRFS-PROGS] [BUG] Fix Bug to corrupt the img file Reply-To: dave@jikos.cz David Sterba
@ 2012-10-25 23:36   ` Rock Lee
  0 siblings, 0 replies; 3+ messages in thread
From: Rock Lee @ 2012-10-25 23:36 UTC (permalink / raw)
  To: Rock Lee, linux-btrfs

Thanks for your review.

Sorry for the problem line wrapped, I will resend the patch.


Thanks
-Rock

2012/10/26 David Sterba <dave@jikos.cz>:
> On Fri, Oct 26, 2012 at 12:12:24AM +0800, Rock Lee wrote:
>> Fix Bug to corrupt the img file
>>
>> Reproduce steps:
>>   > dd if=/dev/zero of=btrfs-small.img bs=1M count=1
>>   > ls -lh btrfs-small.img
>>   -rw-rw-r--. 1 rock rock 1.0M Oct 24 09:51 btrfs-small.img
>>                                       ^^^
>>   > mkfs.btrfs btrfs-small.img
>>   -rw-rw-r--. 1 rock rock 2.0M Oct 24 09:53 btrfs-small.img
>>                                       ^^^
>>
>> Here you can see the original img file's size goes larger to 2Mb.
>
> Thanks, fixes this particular bug; although it crashes later at
>
>   mkfs.btrfs: volumes.c:796: btrfs_alloc_chunk: Assertion `!(ret)' failed
>
> but this is a separate issue and you've sent patches for that IIRC.
>
>> --- a/utils.c
>> +++ b/utils.c
>> @@ -557,6 +557,12 @@ int btrfs_prepare_device(int fd, char *file, int
>> zero_end, u64 *block_count_ret,
>>         }
>>         if (max_block_count)
>>                 block_count = min(block_count, max_block_count);
>> +
>> +       if (block_count < 2 * 1024 * 1024) {
>> +               fprintf(stderr, "size of %s is too small(less than
>> 2Mb)\n", file);
>
> line wrapped, please check your mailer (easy to fix but additional
> unnecessary work)
>
>> +               exit(1);
>> +       }
>> +
>
> Otherwise ack from me.
>
> david

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2012-10-25 23:37 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-10-25 16:12 [PATCH V2][BTRFS-PROGS] [BUG] Fix Bug to corrupt the img file Rock Lee
2012-10-25 16:43 ` [PATCH V2][BTRFS-PROGS] [BUG] Fix Bug to corrupt the img file Reply-To: dave@jikos.cz David Sterba
2012-10-25 23:36   ` Rock Lee

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).