Skip to content

minio.Object violates io.Seeker contract #2155

@opengs

Description

@opengs

Violation of io.Seeker contract

According to Go's io.Seeker documentation:

Seeking to an offset before the start of the file is an error. Seeking to any positive offset may be allowed, but if the new offset exceeds the size of the underlying object, the behavior of subsequent I/O operations is implementation-dependent.

Currently, minio.Object does not respect this contract (its not possible to seek to any positive offset), making it incompatible with standard Go I/O expectations.

How to reproduce

Use tests from standard library testing/iotest. minio.Object returned by GetObject will fail on those tests.

Currently, it fails with:

Seek(-1, 1) from EOF = 0, Negative position not allowed for 1, want 39, nil

The issue likely originates here:

if offset < 0 && whence != 2 {

Since testing/iotest is part of the standard Go library, this behavior prevents minio.Object from being safely used in other libraries that rely on standard I/O behavior.

Proposed solution:

	// Negative offset not valid for whence of '0'.
	if offset < 0 && whence == 0 {
		return 0, errInvalidArgument("Negative position not allowed for 0")
	}

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