From: Hyunchul Lee <hyc.lee@gmail.com>
To: Zhan Xusheng <zhanxusheng1024@gmail.com>
Cc: Namjae Jeon <linkinjeon@kernel.org>,
ntfs@lists.linux.dev, linux-kernel@vger.kernel.org,
Zhan Xusheng <zhanxusheng@xiaomi.com>
Subject: Re: [PATCH] ntfs: widen the sub-block offsets in ntfs_decompress()
Date: Mon, 12 Oct 2026 09:49:55 +0900 [thread overview]
Message-ID: <aswus4M5zs8OxMPG@hyunchul-PC02> (raw)
In-Reply-To: <20261009075523.3135206-1-zhanxusheng@xiaomi.com>
On Fri, Oct 09, 2026 at 03:55:23PM +0800, Zhan Xusheng wrote:
> ntfs_decompress() tracks where the current sub-block starts and ends
> inside the destination page with two u16s:
>
> u16 do_sb_start;
> u16 do_sb_end;
> ...
> do_sb_start = *dest_ofs;
> do_sb_end = do_sb_start + NTFS_SB_SIZE;
>
> *dest_ofs is an int page offset masked with ~PAGE_MASK, and
> NTFS_SB_SIZE is 0x1000, so do_sb_end needs PAGE_SIZE + 0xfff of range.
> That exceeds u16 once PAGE_SIZE reaches 0x10000: the last sub-block of a
> page starts at 0xf000 and do_sb_end wraps from 0x10000 to 0.
>
> The zero-fill that pads a short sub-block then computes a negative
> length:
>
> if (dp_addr < dp_sb_end) {
> int nr_bytes = do_sb_end - *dest_ofs;
>
> memset(dp_addr, 0, nr_bytes);
>
> A sub-block made only of symbol tokens reaches this without consulting
> do_sb_end on the way, because that path just does
>
> *dp_addr++ = *cb++;
> ++*dest_ofs;
>
> and is bounded by dp_addr against dp_sb_end. With do_sb_start at 0xf000
> and eight literal bytes emitted, nr_bytes is -61448 and the memset()
> runs for 18446744073709490168 bytes.
>
> Getting there is cheap: fifteen sub-blocks of eleven bytes each advance
> *dest_ofs to 0xf000, since the same zero-fill pads each of them out to
> 0x1000 while do_sb_end is still exact, and the sixteenth one triggers
> the wrap. A compression block is 0x10000 bytes with 4 KiB clusters and
> the fixed compression unit of 4, so all sixteen fit with room to spare.
>
> Phrase tokens are bounded against do_sb_end and so return -EOVERFLOW
> instead, and the
>
> if (*dest_index == dest_max_index && do_sb_end > dest_max_ofs)
>
> check at the top of the sub-block stops firing for the same reason.
>
> Use int for both, matching *dest_ofs and dest_max_ofs. The narrow type
> came in with the original import and survived the removal and revert of
> the driver.
>
> Signed-off-by: Zhan Xusheng <zhanxusheng@xiaomi.com>
> Fixes: 1e9ea7e04472 ("Revert "fs: Remove NTFS classic"")
Looks good to me.
Reviewed-by: Hyunchul Lee <hyc.lee@gmail.com>
--
Thanks,
Hyunchul
prev parent reply other threads:[~2026-10-12 0:50 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-09 7:55 Zhan Xusheng
2026-10-10 1:15 ` liubaolin
2026-10-12 0:49 ` Hyunchul Lee [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=aswus4M5zs8OxMPG@hyunchul-PC02 \
--to=hyc.lee@gmail.com \
--cc=linkinjeon@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=ntfs@lists.linux.dev \
--cc=zhanxusheng1024@gmail.com \
--cc=zhanxusheng@xiaomi.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®