Skip to content

cron.ParseStandard("TZ=0") causes panic #554

Open

Description

@PersistentJZH

Description

Calling cron.ParseStandard("TZ=0") causes a panic instead of returning an error.

Steps to Reproduce

package main
import "github.com/robfig/cron/v3"

func main() {
    cron.ParseStandard("TZ=0")  // Panics
}

Problem

This is problematic in production environments where:

  • Users provide cron expressions as input
  • A panic can crash the entire service
  • Fuzz testing scenarios can easily trigger this panic

Expected Behavior

can return an error for invalid input instead of panic? like:

parser, err := cron.ParseStandard("TZ=0")
if err != nil {
    return fmt.Errorf("invalid cron expression: %w", err)
}

Environment

  • Go version: 1.21+
  • cron library version: latest
  • OS: macOS m1

Activity

  1. CybotTM commented on Dec 4, 2025

    @CybotTM

    Solution available in maintained fork

    This issue has been fixed in netresearch/go-cron, a maintained fork of this library.

    Fix: Added validation for timezone format before calling time.LoadLocation() - returns error instead of panicking.

    How to migrate:

    // Change import from:
    import "github.com/robfig/cron/v3"
    
    // To:
    import cron "github.com/netresearch/go-cron"

    The API is 100% backward compatible. See the migration guide for details.

    Related: netresearch#14

  2. added a commit that references this issue on Apr 12, 2026
    225cb3b
  3. fitzyracing1 commented on Oct 8, 2026

    @fitzyracing1

    This is fixed in github.com/fitzyracing1/cron/v3 v3.0.2, which is v3.0.1 plus only this fix: a spec that is just a timezone prefix (TZ=0, TZ=UTC, CRON_TZ=Asia/Tokyo, TZ=) now returns missing schedule after timezone: <spec> instead of panicking. Every spec that parsed before parses the same way. To swap it in without touching your imports (this also covers dependencies that import robfig/cron):

    replace github.com/robfig/cron/v3 => github.com/fitzyracing1/cron/v3 v3.0.2
    

    Details and tests: https://github.com/fitzyracing1/cron. Happy to drop it if upstream tags a release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions