Skip to content

[Bug] r3.gwflow crashes when optional sink parameter is not provided #6142

@jayneel-shah18

Description

@jayneel-shah18

Describe the bug

The r3.gwflow module crashes with a segmentation fault when the sink parameter is not provided, despite being marked as optional in the documentation and parser.

To reproduce

  1. Start GRASS and set a 3D region:

    g.region res=10 res3=10 n=100 s=0 e=100 w=0 t=50 b=0
  2. Create minimal input maps:

    r3.mapcalc expression="phead = 50" --o
    r3.mapcalc expression="status = 1" --o
    r3.mapcalc expression="hydcond = 0.0001" --o
    r3.mapcalc expression="syield = 0.001" --o
  3. Run r3.gwflow without providing the sink parameter:

    r3.gwflow phead=phead status=status hc_x=hydcond hc_y=hydcond \
             hc_z=hydcond yield=syield output=result velocity_x=vx \
             velocity_y=vy velocity_z=vz budget=budget
  4. Observe the segmentation fault.

Expected behavior

If sink is not provided, the module should:

  • Either gracefully fall back to using a zero-valued sink field internally,
  • Or document sink as a required parameter and fail with a clear error message if omitted.

Screenshots

Image

System description

  • Operating System: Windows Subsystem for Linux (WSL)
  • GRASS GIS version: 8.4
  • details about further software components
    • GRASS 8.5.0dev
    • Python verison: 3.10.12
    • wxPython version: 4.2.2

Possible Root Cause

The issue appears to come from the unconditional access of param.q->answer in the C source (main.c), even when sink is not set by the user. This leads to dereferencing a NULL pointer and crashing the module.

I would be happy to submit a patch for this, either to:

  • Add null-checks and initialize a zero-valued map internally if unset, or
  • Update the parser and docs to mark sink as required.

Looking forward to making the preferred change.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions