html_url,issue_url,id,node_id,user,created_at,updated_at,author_association,body,reactions,performed_via_github_app,issue https://github.com/pydata/xarray/issues/6813#issuecomment-1204344123,https://api.github.com/repos/pydata/xarray/issues/6813,1204344123,IC_kwDOAMm_X85HyNU7,38170479,2022-08-03T18:45:04Z,2022-08-03T18:45:04Z,CONTRIBUTOR,@djhoese Is that not already an existing problem since `filename_or_obj.seek(0)` is called in the existing code after reading the magic number?,"{""total_count"": 0, ""+1"": 0, ""-1"": 0, ""laugh"": 0, ""hooray"": 0, ""confused"": 0, ""heart"": 0, ""rocket"": 0, ""eyes"": 0}",,1310058435 https://github.com/pydata/xarray/issues/6813#issuecomment-1189589335,https://api.github.com/repos/pydata/xarray/issues/6813,1189589335,IC_kwDOAMm_X85G57FX,38170479,2022-07-19T21:55:51Z,2022-07-20T14:56:33Z,CONTRIBUTOR,"Note that the second example fails on the first open_dataset, which I assume is expected since it's not mode `mode='rb'`","{""total_count"": 0, ""+1"": 0, ""-1"": 0, ""laugh"": 0, ""hooray"": 0, ""confused"": 0, ""heart"": 0, ""rocket"": 0, ""eyes"": 0}",,1310058435 https://github.com/pydata/xarray/issues/6813#issuecomment-1189593287,https://api.github.com/repos/pydata/xarray/issues/6813,1189593287,IC_kwDOAMm_X85G58DH,38170479,2022-07-19T22:00:48Z,2022-07-19T22:00:48Z,CONTRIBUTOR,"Adding `filename_or_obj.seek(0)` fixes this, but I am not sure if it poses a security risk? ``` def read_magic_number_from_file(filename_or_obj, count=8) -> bytes: # check byte header to determine file type if isinstance(filename_or_obj, bytes): magic_number = filename_or_obj[:count] elif isinstance(filename_or_obj, io.IOBase): filename_or_obj.seek(0) if filename_or_obj.tell() != 0: raise ValueError( ""cannot guess the engine, "" ""file-like object read/write pointer not at the start of the file, "" ""please close and reopen, or use a context manager"" ) magic_number = filename_or_obj.read(count) filename_or_obj.seek(0) else: raise TypeError(f""cannot read the magic number form {type(filename_or_obj)}"") return magic_number ```","{""total_count"": 0, ""+1"": 0, ""-1"": 0, ""laugh"": 0, ""hooray"": 0, ""confused"": 0, ""heart"": 0, ""rocket"": 0, ""eyes"": 0}",,1310058435