Fix #95411: "//" temp directory prefix causing crash #118872

Closed
Campbell Barton wants to merge 3 commits from ideasman42:pr-temp-dir-sanitize into main

When changing the target branch, be careful to rebase the branch in your fork to match. See documentation.
  • Skip leading forward slashes when setting the temp directory.
  • Add a utility function to set the temporary directory
    which is used for the user preferences & environment variables.

This is an alternative fix to #118856 which ignores these directories.

Since temporary directories may be set via environment variables & "//example/tmp/" is a valid path, I'd suggest to support these paths.

After this PR the following works:

env TMPDIR="//tmp/foo" blender --factory-startup --python-expr "print("Temp:", __import__('bpy').app.tempdir)"

Temp: /tmp/foo/blender_YyTCaH/ is printed.

- Skip leading forward slashes when setting the temp directory. - Add a utility function to set the temporary directory which is used for the user preferences & environment variables. ---- This is an alternative fix to #118856 which ignores these directories. Since temporary directories may be set via environment variables & "//example/tmp/" is a valid path, I'd suggest to support these paths. After this PR the following works: ``` env TMPDIR="//tmp/foo" blender --factory-startup --python-expr "print("Temp:", __import__('bpy').app.tempdir)" ``` `Temp: /tmp/foo/blender_YyTCaH/` is printed.
Campbell Barton requested review from Philipp Oeser 2024-02-28 23:56:37 +01:00
Campbell Barton requested review from Bastien Montagne 2024-02-28 23:56:38 +01:00
Campbell Barton added the
Interest
Pipeline, Assets & IO
label 2024-02-28 23:56:52 +01:00
Campbell Barton force-pushed pr-temp-dir-sanitize from 2697eff0e5 to 0d0d6ea0c2 2024-02-28 23:58:08 +01:00 Compare
Campbell Barton force-pushed pr-temp-dir-sanitize from 0d0d6ea0c2 to 2048825d44 2024-02-29 00:02:57 +01:00 Compare
Campbell Barton force-pushed pr-temp-dir-sanitize from 2048825d44 to 0b3b35683a 2024-02-29 00:26:16 +01:00 Compare
Member

After putting in // for Temporary Files

image

I am still getting a warning (similar to without this patch -- now a single slash)

WARN (bke.appdir): source/blender/blenkernel/intern/appdir.cc:1160 tempdir_session_create: Could not generate a temp file name for '/blender_f0jAHj', falling back to '/'

Collada still crashes.

The output of the following also seems wrong

env TMPDIR="//" ./bin/blender --factory-startup --python-expr "print('Temp:', __import__('bpy').app.tempdir)"
WARN (bke.appdir): source/blender/blenkernel/intern/appdir.cc:1160 tempdir_session_create: Could not generate a temp file name for '/blender_4WKfHw', falling back to '/'
Temp: /
env TMPDIR="//tmp/foo" ./bin/blender --factory-startup --python-expr "print('Temp:', __import__('bpy').app.tempdir)"
Temp: /tmp/blender_ve6XoD/
After putting in `//` for `Temporary Files` ![image](/attachments/4878692b-afa6-4bd5-b791-7538614fb3c0) I am still getting a warning (similar to without this patch -- now a single slash) `WARN (bke.appdir): source/blender/blenkernel/intern/appdir.cc:1160 tempdir_session_create: Could not generate a temp file name for '/blender_f0jAHj', falling back to '/'` Collada still crashes. The output of the following also seems wrong ``` env TMPDIR="//" ./bin/blender --factory-startup --python-expr "print('Temp:', __import__('bpy').app.tempdir)" WARN (bke.appdir): source/blender/blenkernel/intern/appdir.cc:1160 tempdir_session_create: Could not generate a temp file name for '/blender_4WKfHw', falling back to '/' Temp: / ``` ``` env TMPDIR="//tmp/foo" ./bin/blender --factory-startup --python-expr "print('Temp:', __import__('bpy').app.tempdir)" Temp: /tmp/blender_ve6XoD/ ```
5.1 KiB
Campbell Barton force-pushed pr-temp-dir-sanitize from 0b3b35683a to 958024b7c6 2024-02-29 10:56:24 +01:00 Compare
Author
Owner

@lichtwerk this patch makes it so //path becomes /path, however // also becomes /.

Entering / on it's own also has this problem, unrelated to relative paths.

I've added a check that the temporary directory is writable, so that means directories without permissions to write will be rejected, although we could consider the issue of "users pointing the temp directory to a path they don't have permissions to write to" separate from paths being interpreted as relative.


Further, Collada crashing without write permissions is suspicious, a file system may fail to write for all sorts of reasons, Blender should report an error that the operation failed - instead of crashing, but that's a separate issue.

@lichtwerk this patch makes it so `//path` becomes `/path`, however `//` also becomes `/`. Entering `/` on it's own also has this problem, unrelated to relative paths. I've added a check that the temporary directory is writable, so that means directories without permissions to write will be rejected, although we could consider the issue of _"users pointing the temp directory to a path they don't have permissions to write to"_ separate from paths being interpreted as relative. ---- Further, Collada crashing without write permissions is suspicious, a file system may fail to write for all sorts of reasons, Blender should report an error that the operation failed - instead of crashing, but that's a separate issue.
Bastien Montagne reviewed 2024-02-29 11:11:41 +01:00
Bastien Montagne left a comment
Owner

From a logical PoV, change LGTM.

Wondering if we should not try to use actual C++ for such new code (although it does add a bit of pain to use it in C-code context...)? And effectively converting the file to C++ one of course.

Something like std::optional<std::string> blender::temp_directory_path_copy_if_valid(blender::StringRefNull dirpath); maybe?

@HooglyBoogly would know better about that though.

From a logical PoV, change LGTM. Wondering if we should not try to use actual C++ for such new code (although it does add a bit of pain to use it in C-code context...)? And effectively converting the file to C++ one of course. Something like `std::optional<std::string> blender::temp_directory_path_copy_if_valid(blender::StringRefNull dirpath);` maybe? @HooglyBoogly would know better about that though.
Campbell Barton added 1 commit 2024-02-29 11:36:21 +01:00
d225044858 Revert "Check the temporary directory is writable before setting"
This reverts commit 958024b7c6.

I'd rather handle permissions separately from relative paths.
Philipp Oeser approved these changes 2024-02-29 11:46:22 +01:00
Philipp Oeser left a comment
Member

discussed a bit further in chat, accepting (but since Collada will still crash on certain input, will look into separate fix for that...)

discussed a bit further in chat, accepting (but since Collada will still crash on certain input, will look into separate fix for that...)
Author
Owner

Committed c19cdc343f, closing.

Committed c19cdc343f9a8ffae89146fbf80e6152a340562b, closing.
Campbell Barton closed this pull request 2024-02-29 12:05:43 +01:00

Pull request closed

Sign in to join this conversation.
No reviewers
No Label
Interest
Alembic
Interest
Animation & Rigging
Interest
Asset Browser
Interest
Asset Browser Project Overview
Interest
Audio
Interest
Automated Testing
Interest
Blender Asset Bundle
Interest
BlendFile
Interest
Collada
Interest
Compatibility
Interest
Compositing
Interest
Core
Interest
Cycles
Interest
Dependency Graph
Interest
Development Management
Interest
EEVEE
Interest
EEVEE & Viewport
Interest
Freestyle
Interest
Geometry Nodes
Interest
Grease Pencil
Interest
ID Management
Interest
Images & Movies
Interest
Import Export
Interest
Line Art
Interest
Masking
Interest
Metal
Interest
Modeling
Interest
Modifiers
Interest
Motion Tracking
Interest
Nodes & Physics
Interest
OpenGL
Interest
Overlay
Interest
Overrides
Interest
Performance
Interest
Physics
Interest
Pipeline, Assets & IO
Interest
Platforms, Builds & Tests
Interest
Python API
Interest
Render & Cycles
Interest
Render Pipeline
Interest
Sculpt, Paint & Texture
Interest
Text Editor
Interest
Translations
Interest
Triaging
Interest
Undo
Interest
USD
Interest
User Interface
Interest
UV Editing
Interest
VFX & Video
Interest
Video Sequencer
Interest
Virtual Reality
Interest
Vulkan
Interest
Wayland
Interest
Workbench
Interest: X11
Legacy
Blender 2.8 Project
Legacy
Milestone 1: Basic, Local Asset Browser
Legacy
OpenGL Error
Meta
Good First Issue
Meta
Papercut
Meta
Retrospective
Meta
Security
Module
Animation & Rigging
Module
Core
Module
Development Management
Module
EEVEE & Viewport
Module
Grease Pencil
Module
Modeling
Module
Nodes & Physics
Module
Pipeline, Assets & IO
Module
Platforms, Builds & Tests
Module
Python API
Module
Render & Cycles
Module
Sculpt, Paint & Texture
Module
Triaging
Module
User Interface
Module
VFX & Video
Platform
FreeBSD
Platform
Linux
Platform
macOS
Platform
Windows
Priority
High
Priority
Low
Priority
Normal
Priority
Unbreak Now!
Status
Archived
Status
Confirmed
Status
Duplicate
Status
Needs Info from Developers
Status
Needs Information from User
Status
Needs Triage
Status
Resolved
Type
Bug
Type
Design
Type
Known Issue
Type
Patch
Type
Report
Type
To Do
No Milestone
No project
No Assignees
3 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: blender/blender#118872
No description provided.