Skip to content

🐛 [Bug]: Fiber crashes on non-amd64/arm64 architectures because of unsafe .rodata check #3771

@Doout

Description

@Doout

Bug Description

When building Fiber for non-amd64/arm64 architectures (e.g., s390x, ppc64, ppc64le), the change introduced in PR #3703 causes runtime crashes due to alignment faults.

At runtime, Fiber panics with errors such as:

github.com/gofiber/fiber/v3.(*App).GetString: runtime.erodata+41911353 is not 2-byte aligned
github.com/gofiber/fiber/v3.(*App).GetBytes: runtime.erodata+41911353 is not 2-byte aligned
github.com/gofiber/fiber/v3.(*DefaultReq).Body: runtime.erodata+41911353 is not 2-byte aligned
github.com/gofiber/fiber/v3.(*DefaultReq).Params: runtime.erodata+41911353 is not 2-byte aligned
github.com/gofiber/fiber/v3.(*DefaultReq).getBody: runtime.erodata+41911353 is not 2-byte aligned

How to Reproduce

Steps to reproduce the behavior:

  1. Create a minimal Fiber app:
package main

import "github.com/gofiber/fiber/v3"

func main() {
    app := fiber.New()

    // Route that uses Params
    app.Get("/user/:id", func(c fiber.Ctx) error {
        // This will hit DefaultReq.Params internally
        return c.SendString("ID = " + c.Params("id"))
    })

    // Route that uses Body
    app.Post("/echo", func(c fiber.Ctx) error {
        // This will hit DefaultReq.Body internally
        return c.Send(c.Body())
    })

    app.Listen(":3000")
}
  1. Cross-compile the app for s390x:

    GOARCH=s390x GOOS=linux go build -o app .
  2. Observed behavior:
    The build fails with alignment errors similar to:

    github.com/gofiber/fiber/v3.(*DefaultReq).Body: runtime.erodata+6358137 is not 2-byte aligned
    github.com/gofiber/fiber/v3.(*DefaultReq).Params: runtime.erodata+6358137 is not 2-byte aligned
    github.com/gofiber/fiber/v3.(*DefaultReq).getBody: runtime.erodata+6358137 is not 2-byte aligned
    

Expected behavior:
The build should succeed and produce a binary.

Actual behavior:
The build fails immediately due to unsafe .rodata checks that are not valid on strict-alignment architectures (s390x, ppc64, etc.).

Expected Behavior

The build should succeed and produce a binary.

Fiber Version

v3.0.0-rc.2

Code Snippet (optional)

package main

import "github.com/gofiber/fiber/v3"

func main() {
    app := fiber.New()

    // Route that uses Params
    app.Get("/user/:id", func(c fiber.Ctx) error {
        // This will hit DefaultReq.Params internally
        return c.SendString("ID = " + c.Params("id"))
    })

    // Route that uses Body
    app.Post("/echo", func(c fiber.Ctx) error {
        // This will hit DefaultReq.Body internally
        return c.Send(c.Body())
    })

    app.Listen(":3000")
}

Checklist:

  • I agree to follow Fiber's Code of Conduct.
  • I have checked for existing issues that describe my problem prior to opening this one.
  • I understand that improperly formatted bug reports may be closed without explanation.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions