Re: [PATCH] check: check so offset is not bigger then the leaf

David Sterba
2015-06-25T16:49:59Z

On Thu, Jun 25, 2015 at 09:24:10AM -0700, Josef Bacik wrote:
> > +
> > + for (i = 0; i < nritems; i++) {
> > + void *tmp;
> > +
> > + tmp = btrfs_item_ptr(buf, i, void);
> > + if ((long)tmp >= BTRFS_LEAF_DATA_SIZE(root)) {
> > + ret = BTRFS_TREE_BLOCK_INVALID_OFFSETS;
> > + fprintf(stderr, "bad item pointer %lu\n",
> > + (long)tmp);
> > + goto fail;
> > + }
> > + }
>
> I'd just do
>
> if (btrfs_item_end_nr(buf, i) >= BTRFS_LEAF_DATA_SIZE(root))
>
> that way you catch problems with offset and size. Thanks,

Ah right, my check would not catch 'offset + size >= leaf data size'
if 'offset < leaf data size'. Patch welcome.