Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OSError preadv() #81690

Closed
YoSTEALTH mannequin opened this issue Jul 5, 2019 · 2 comments
Closed

OSError preadv() #81690

YoSTEALTH mannequin opened this issue Jul 5, 2019 · 2 comments
Labels
3.8 only security fixes type-bug An unexpected behavior, bug, or error

Comments

@YoSTEALTH
Copy link
Mannequin

YoSTEALTH mannequin commented Jul 5, 2019

BPO 37509
Nosy @vstinner, @YoSTEALTH, @pablogsal

Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

Show more details

GitHub fields:

assignee = None
closed_at = <Date 2019-12-25.15:43:58.290>
created_at = <Date 2019-07-05.17:50:39.691>
labels = ['invalid', 'type-bug', '3.8']
title = 'OSError preadv()'
updated_at = <Date 2019-12-25.15:43:58.290>
user = 'https://github.com/YoSTEALTH'

bugs.python.org fields:

activity = <Date 2019-12-25.15:43:58.290>
actor = 'YoSTEALTH'
assignee = 'none'
closed = True
closed_date = <Date 2019-12-25.15:43:58.290>
closer = 'YoSTEALTH'
components = []
creation = <Date 2019-07-05.17:50:39.691>
creator = 'YoSTEALTH'
dependencies = []
files = []
hgrepos = []
issue_num = 37509
keywords = []
message_count = 2.0
messages = ['347364', '358869']
nosy_count = 3.0
nosy_names = ['vstinner', 'YoSTEALTH', 'pablogsal']
pr_nums = []
priority = 'normal'
resolution = 'not a bug'
stage = 'resolved'
status = 'closed'
superseder = None
type = 'behavior'
url = 'https://bugs.python.org/issue37509'
versions = ['Python 3.8']

@YoSTEALTH
Copy link
Mannequin Author

YoSTEALTH mannequin commented Jul 5, 2019

import os
import ctypes

# Stdlib
# ------

def test_preadv_stdlib(path):
    fd = os.open(path, os.O_RDWR | os.O_CREAT)
    buffer = bytearray(10)
    buffers = [buffer]
    try:
        length = os.preadv(fd, buffers, 0, os.RWF_NOWAIT)
        # OSError: [Errno 95] Operation not supported
        print('length:', length)
        print('buffer:', buffer)
    finally:
        os.close(fd)

# Cyptes Libc
# -----------

class iovec(ctypes.Structure):
    _fields_ = [('iov_base', ctypes.c_char_p), ('iov_len', ctypes.c_size_t)]


libc = ctypes.CDLL('libc.so.6')


def test_preadv_libc(path):
    fd = os.open(path, os.O_RDWR | os.O_CREAT)
    buffer = bytes(10)
    buffers = (iovec*1)()
    buffers[0].iov_base = buffer
    buffers[0].iov_len = 10
    try:
        length = libc.preadv2(fd, buffers, len(buffers), 0, os.RWF_NOWAIT)
        print('length:', length)  # length: -1
        print('buffer:', buffer)  # buffer: b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'
    finally:
        os.close(fd)

# Test Run
# --------

def test():
    path = '/dev/shm/test-preadv-in-ram-file'
# Test-1 stdlib implementation
try:
    test_preadv_stdlib(path)  # OSError: [Errno 95] Operation not supported
except OSError:
    print('OSError is raised. This should not raise OSError')
    # Test-2 custom ctype `libc` implementation
    test_preadv_libc(path)


if __name__ == '__main__':
    test()

This code is just to demonstrate working vs receiving an OSError in this specific usage.

System: Linux 4.19.56-1-MANJARO
Python: 3.8.0b2

When the file in question is stored in ram ('/dev/shm') stdlib implementation raises an OSError while libc version does not.

@YoSTEALTH YoSTEALTH mannequin added 3.8 only security fixes type-bug An unexpected behavior, bug, or error labels Jul 5, 2019
@YoSTEALTH
Copy link
Mannequin Author

YoSTEALTH mannequin commented Dec 25, 2019

I am closing this topic as its right for python to raise OSError as -errno must be assigned to e.g. OSError(-errno, os.strerror(-errno)) to raise appropriate exception.

@YoSTEALTH YoSTEALTH mannequin closed this as completed Dec 25, 2019
@YoSTEALTH YoSTEALTH mannequin added the invalid label Dec 25, 2019
@ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3.8 only security fixes type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

0 participants