Skip to content

fix: guard group<=0 in ConvolutionDepthWise(::1D)::load_param to avoid FPE divide-by-zero (#6911) - #6919

Closed
FluxMind-O wants to merge 1 commit into
Tencent:masterfrom
FluxMind-O:fix/convolutiondepthwise-fpe-group-zero
Closed

fix: guard group<=0 in ConvolutionDepthWise(::1D)::load_param to avoid FPE divide-by-zero (#6911)#6919
FluxMind-O wants to merge 1 commit into
Tencent:masterfrom
FluxMind-O:fix/convolutiondepthwise-fpe-group-zero

Conversation

@FluxMind-O

Copy link
Copy Markdown

Summary

Fixes #6911 — FPE divide-by-zero in ConvolutionDepthWise::load_param when a malformed param file provides group == 0.

Problem

When group == 0, the existing guard num_output % group != 0 itself performs an integer division by zero, triggering SIGFPE (FPE divide-by-zero) before the rejection path is reached. The CPU and 1D variants of ConvolutionDepthWise::load_param were missing the group <= 0 check that the Vulkan int8 path already had (convolutiondepthwise_vulkan.cpp:597).

Fix

Add a group <= 0 short-circuit guard before the modulo in both affected load_param implementations, returning -100 (the existing "reject invalid group" code) without performing the division:

if (group <= 0 || num_output % group != 0)
{
    // reject invalid group
    return -100;
}
  • src/layer/convolutiondepthwise.cpp — CPU ConvolutionDepthWise::load_param
  • src/layer/convolutiondepthwise1d.cppConvolutionDepthWise1D::load_param

The Vulkan variant calls the CPU load_param, so it is covered transitively. group < 0 is rejected too (defensive), matching the spirit of the existing guard. Normal-path behavior is unchanged: valid group > 0 with num_output % group == 0 still returns 0.

Regression tests

  • tests/test_convolutiondepthwise_invalid.cpp — asserts load_param returns -100 for group = 0, -1, -8.
  • tests/test_convolutiondepthwise1d_invalid.cpp — same for the 1D variant.

Verification

Checklist

  • one clear bug -> one local fix -> one regression test
  • no change to normal-path behavior
  • no architecture / API change

…d FPE divide-by-zero

When group == 0, the existing guard num_output % group != 0 itself performs
integer division by zero, triggering SIGFPE before the rejection path is
reached (issue Tencent#6911). The Vulkan int8 path already checked group == 0; the
CPU and 1D load_param variants did not.

Add a group <= 0 short-circuit before the modulo in both affected
implementations, returning -100 (the existing reject-invalid-group code)
without performing the division. group < 0 is rejected too (defensive).
Normal-path behavior is unchanged.

- src/layer/convolutiondepthwise.cpp: CPU ConvolutionDepthWise::load_param
- src/layer/convolutiondepthwise1d.cpp: ConvolutionDepthWise1D::load_param

Regression tests:
- tests/test_convolutiondepthwise_invalid.cpp
- tests/test_convolutiondepthwise1d_invalid.cpp
  assert load_param returns -100 for group = 0, -1, -8.

Verified: before fix the new test aborts with SIGFPE (exit 136); after fix
both new tests pass and existing test_convolutiondepthwise(_1/_oom) and
test_convolutiondepthwise1d still pass.
@tencent-adm

Copy link
Copy Markdown
Member

CLA assistant check
Thank you for your submission, we really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

@FluxMind-O

Copy link
Copy Markdown
Author

Closing as duplicate — my apologies to the maintainers.

After opening this I found that #6912 by @beilzx already fixes #6911 (same group == 0 guard on the CPU + 1D load_param paths, CLA signed, open for review). There is no value in keeping a second PR for the same one-line guard, so I'm withdrawing this one to avoid wasting reviewer time.

Thanks @beilzx for the prompt fix. I'll go review #6912 instead.

@FluxMind-O FluxMind-O closed this Aug 17, 2026
@FluxMind-O
FluxMind-O deleted the fix/convolutiondepthwise-fpe-group-zero branch August 17, 2026 21:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug: FPE (divide-by-zero) in ConvolutionDepthWise::load_param (src/layer/convolutiondepthwise.cpp:46)

2 participants