Skip to content

UBSAN: fseek() on php://memory with PHP_INT_MIN causes undefined behavior #20964

@arshidkv12

Description

@arshidkv12

Description

The following code:

<?php
$stream = fopen('php://memory', 'r+');
$result = fseek($stream, PHP_INT_MIN, SEEK_END);
var_dump($result);

Resulted in this output:

/Users/arshid/Downloads/php-src/main/streams/memory.c:168:45: runtime error: negation of -9223372036854775808 cannot be represented in type 'zend_off_t' (aka 'long long'); cast to an unsigned type to negate this value to itself
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior /Users/arshid/Downloads/php-src/main/streams/memory.c:168:45 
[4]    93646 abort      sapi/cli/php z.php

But I expected this output instead:

-1

PHP Version

PHP 8.6.0-dev (cli) (built: Jan 18 2026 08:54:52) (NTS DEBUG)
Copyright (c) The PHP Group
Zend Engine v4.6.0-dev, Copyright (c) Zend Technologies
    with Zend OPcache v8.6.0-dev, Copyright (c), by Zend Technologies

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions