René's URL Explorer Experiment


Title: Add ability for static search locations · Issue #41 · scijava/native-lib-loader · GitHub

Open Graph Title: Add ability for static search locations · Issue #41 · scijava/native-lib-loader

X Title: Add ability for static search locations · Issue #41 · scijava/native-lib-loader

Description: Summary The native-lib-loader should allow specifying a library in a static location for edge-case scenarios, usually imposed by security restrictions, constraints or sandboxing. Edit: Static locations may also offer slight performance b...

Open Graph Description: Summary The native-lib-loader should allow specifying a library in a static location for edge-case scenarios, usually imposed by security restrictions, constraints or sandboxing. Edit: Static locat...

X Description: Summary The native-lib-loader should allow specifying a library in a static location for edge-case scenarios, usually imposed by security restrictions, constraints or sandboxing. Edit: Static locat...

Opengraph URL: https://github.com/scijava/native-lib-loader/issues/41

X: @github

direct link

Domain: github.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Add ability for static search locations","articleBody":"### Summary\r\n\r\nThe `native-lib-loader` should allow specifying a library in a static location for edge-case scenarios, usually imposed by security restrictions, constraints or sandboxing.\r\n\r\n**Edit:** Static locations may also offer slight performance benefits as well, eliminating the need for unzipping (CPU/disk) activity, see discussion [here](https://github.com/scijava/native-lib-loader/pull/32#issuecomment-887728011).\r\n\r\n### Details\r\n\r\nTechnically, `native-lib-loader` allows for static search locations, but it requires implementing the `JniExtractor` class or overriding the behavior of the `DefaultJniExractor` class, as -- by design -- they both intend to perform an extract operation prior to loading a native library.  This extraction operation doesn't work in all environments.\r\n\r\nI'll quote a sister project -- JNA -- documentation, I think it words this problem well and explains as to why this can be needed... \r\n\r\n\u003e * When [...] classes are loaded, the native shared library [...] is loaded as well. An attempt is made to load it from the any paths defined in `jna.boot.library.path` (if defined), then the system library path using `System.loadLibrary(java.lang.String)`, unless `jna.nosys=true`.\r\n\u003e * If not found, the appropriate library will be extracted from the class path (into a temporary directory if found within a jar file) and loaded from there, unless `jna.noclasspath=true`.\r\n\u003e * If your system has additional security constraints regarding execution or load of files (`SELinux`, for example), **you should probably install the native library in an accessible location and configure your system accordingly, rather than relying on JNA to extract the library from its own jar file**.\r\n\r\nThe last bullet is the point I'd like to focus on since this same use-case exists for `native-lib-loader`.  For example, if a native library is intended to be distributed with a Java application that's distributed from the Apple AppStore, sandboxing is a hard-requirement, and like the aforementioned SELinux use-case, sandboxing can prevent loading a library from arbitrary locations (such as $TEMP), quoting an Apple employee on the [Apple Developer forums](https://developer.apple.com/forums/thread/22833?answerId=75935022#75935022):\r\n\r\n\u003e I think you’ll run into problems there. Specifically, modern versions of the system prevent an app from referencing libraries outside of the app (other than system libraries). See Gatekeeper Changes in OS X `v10.10.4` and Later in [Technote 2206 OS X Code Signing In Depth](https://developer.apple.com/library/mac/technotes/tn2206/_index.html#//apple_ref/doc/uid/DTS40007919-CH1-TNTAG207)\r\n\r\nFurthermore, the JNA portion \"unless `jna.nosys=true`\", I find to be increasingly important as client environments may have identically named libraries in search paths that the client has little or no control over.  This is a separate issue, but may be tackled as part of the same enhancement.\r\n\r\n### Workaround\r\n\r\nProviding a stub extractor can handle this issue:\r\n\r\n\u003cdetails\u003e\r\n\u003csummary\u003eClick to see \u003ccode\u003eDefaultJniExtractorStub.java\u003c/code\u003e\u003c/summary\u003e\r\n\r\n```java\r\n\r\n/**\r\n * License: https://opensource.org/licenses/BSD-3-Clause\r\n */\r\npackage jssc;\r\n\r\nimport org.scijava.nativelib.DefaultJniExtractor;\r\nimport org.scijava.nativelib.NativeLibraryUtil;\r\n\r\nimport java.io.File;\r\nimport java.io.IOException;\r\n\r\n/**\r\n * @author A. Tres Finocchiaro\r\n *\r\n * Stub \u003ccode\u003eDefaultJniExtractor\u003c/code\u003e class to allow native-lib-loader to conditionally\r\n * use a statically defined native search path \u003ccode\u003ebootPath\u003c/code\u003e when provided.\r\n */\r\npublic class DefaultJniExtractorStub extends DefaultJniExtractor {\r\n    private File bootPath;\r\n    private boolean useStub;\r\n\r\n    /**\r\n     * Default constructor\r\n     */\r\n    public DefaultJniExtractorStub(Class libraryJarClass) throws IOException {\r\n        super(libraryJarClass);\r\n        useStub = false;\r\n    }\r\n\r\n    /**\r\n     * Force native-lib-loader to first look in the location defined as \u003ccode\u003ebootPath\u003c/code\u003e\r\n     * prior to extracting a native library, useful for sandboxed environments.\r\n     *  \u003ccode\u003e\r\n     *  NativeLoader.setJniExtractor(new DefaultJniExtractorStub(null, \"/opt/nativelibs\")));\r\n     *  NativeLoader.loadLibrary(\"mylibrary\");\r\n     *  \u003c/code\u003e\r\n     */\r\n    public DefaultJniExtractorStub(Class libraryJarClass, String bootPath) throws IOException {\r\n        this(libraryJarClass);\r\n        this.bootPath = new File(bootPath);\r\n\r\n        if(bootPath != null) {\r\n            File bootTest = new File(bootPath);\r\n            if(bootTest.exists()) {\r\n                // assume a static, existing directory will contain the native libs\r\n                this.useStub = true;\r\n            } else {\r\n                System.err.println(\"WARNING \" + DefaultJniExtractorStub.class.getCanonicalName() + \": Boot path \" + bootPath + \" not found, falling back to default extraction behavior.\");\r\n            }\r\n        }\r\n    }\r\n\r\n    /**\r\n     * If a \u003ccode\u003ebootPath\u003c/code\u003e was provided to the constructor and exists,\r\n     * calculate the \u003ccode\u003eFile\u003c/code\u003e path without any extraction logic.\r\n     *\r\n     * If a \u003ccode\u003ebootPath\u003c/code\u003e was NOT provided or does NOT exist, fallback on\r\n     * the default extraction behavior.\r\n     */\r\n    @Override\r\n    public File extractJni(String libPath, String libName) throws IOException {\r\n        // Lie and pretend it's already extracted at the bootPath location\r\n        if(useStub) {\r\n            return new File(bootPath, NativeLibraryUtil.getPlatformLibraryName(libName));\r\n        }\r\n        // Fallback on default behavior\r\n        return super.extractJni(libPath, libName);\r\n    }\r\n\r\n    @Override\r\n    public void extractRegistered() throws IOException {\r\n        if(useStub) {\r\n            return; // no-op\r\n        }\r\n        super.extractRegistered();\r\n    }\r\n}\r\n\r\n```\r\n\r\n\u003c/details\u003e\r\n\r\nUsage:\r\n\r\n```diff\r\n+ NativeLoader.setJniExtractor(new DefaultJniExtractorStub(null, \"/opt/libs\"));\r\n  NativeLoader.loadLibrary(\"mylibrary\");\r\n```\r\n\r\n### Caveats\r\n\r\nDue to the library loading order in `native-lib-loader`, any [System locations will be always be preferred](https://docs.oracle.com/javase/7/docs/api/java/lang/System.html#loadLibrary(java.lang.String)), which can cause compatibility issues if the system was modified (probably warrants a separate bug report).\r\n\r\nhttps://github.com/scijava/native-lib-loader/blob/56cdf6200592e06562cc099e583b1dbbc97db6df/src/main/java/org/scijava/nativelib/NativeLoader.java#L134-L142","author":{"url":"https://github.com/tresf","@type":"Person","name":"tresf"},"datePublished":"2021-07-27T16:57:24.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":3},"url":"https://github.com/41/native-lib-loader/issues/41"}

route-pattern/_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format)
route-controllervoltron_issues_fragments
route-actionissue_layout
fetch-noncev2:27fabc1f-7f88-0b83-6b38-f2a9db3ff0c7
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-id8530:5177D:172F3D2:2074427:69692233
html-safe-nonce57f8b0f98820a551cb704dba98433315f8a73c2b79b724b405d174374cf52c94
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4NTMwOjUxNzdEOjE3MkYzRDI6MjA3NDQyNzo2OTY5MjIzMyIsInZpc2l0b3JfaWQiOiI2MDIzMTU5OTI2MDQ3MTg3NTA3IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0=
visitor-hmac58747e8a3b596a6757685efd7b7f2bb88294946bd87b8abcf0ed9f58de547755
hovercard-subject-tagissue:954078648
github-keyboard-shortcutsrepository,issues,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///voltron/issues_fragments/issue_layout
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/scijava/native-lib-loader/41/issue_layout
twitter:imagehttps://opengraph.githubassets.com/6c939939f810346c318e487781bf71f82a0fc5effe83170061e7e697285184a8/scijava/native-lib-loader/issues/41
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/6c939939f810346c318e487781bf71f82a0fc5effe83170061e7e697285184a8/scijava/native-lib-loader/issues/41
og:image:altSummary The native-lib-loader should allow specifying a library in a static location for edge-case scenarios, usually imposed by security restrictions, constraints or sandboxing. Edit: Static locat...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernametresf
hostnamegithub.com
expected-hostnamegithub.com
None54182691a21263b584d2e600b758e081b0ff1d10ffc0d2eefa51cf754b43b51d
turbo-cache-controlno-preview
go-importgithub.com/scijava/native-lib-loader git https://github.com/scijava/native-lib-loader.git
octolytics-dimension-user_id1262770
octolytics-dimension-user_loginscijava
octolytics-dimension-repository_id3805074
octolytics-dimension-repository_nwoscijava/native-lib-loader
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id3805074
octolytics-dimension-repository_network_root_nwoscijava/native-lib-loader
turbo-body-classeslogged-out env-production page-responsive
disable-turbofalse
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
released69ac0477df0f87da03b8b06cebd187012d7a930
ui-targetfull
theme-color#1e2327
color-schemelight dark

Links:

Skip to contenthttps://github.com/scijava/native-lib-loader/issues/41#start-of-content
https://github.com/
Sign in https://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fscijava%2Fnative-lib-loader%2Fissues%2F41
GitHub CopilotWrite better code with AIhttps://github.com/features/copilot
GitHub SparkBuild and deploy intelligent appshttps://github.com/features/spark
GitHub ModelsManage and compare promptshttps://github.com/features/models
MCP RegistryNewIntegrate external toolshttps://github.com/mcp
ActionsAutomate any workflowhttps://github.com/features/actions
CodespacesInstant dev environmentshttps://github.com/features/codespaces
IssuesPlan and track workhttps://github.com/features/issues
Code ReviewManage code changeshttps://github.com/features/code-review
GitHub Advanced SecurityFind and fix vulnerabilitieshttps://github.com/security/advanced-security
Code securitySecure your code as you buildhttps://github.com/security/advanced-security/code-security
Secret protectionStop leaks before they starthttps://github.com/security/advanced-security/secret-protection
Why GitHubhttps://github.com/why-github
Documentationhttps://docs.github.com
Bloghttps://github.blog
Changeloghttps://github.blog/changelog
Marketplacehttps://github.com/marketplace
View all featureshttps://github.com/features
Enterpriseshttps://github.com/enterprise
Small and medium teamshttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
App Modernizationhttps://github.com/solutions/use-case/app-modernization
DevSecOpshttps://github.com/solutions/use-case/devsecops
DevOpshttps://github.com/solutions/use-case/devops
CI/CDhttps://github.com/solutions/use-case/ci-cd
View all use caseshttps://github.com/solutions/use-case
Healthcarehttps://github.com/solutions/industry/healthcare
Financial serviceshttps://github.com/solutions/industry/financial-services
Manufacturinghttps://github.com/solutions/industry/manufacturing
Governmenthttps://github.com/solutions/industry/government
View all industrieshttps://github.com/solutions/industry
View all solutionshttps://github.com/solutions
AIhttps://github.com/resources/articles?topic=ai
Software Developmenthttps://github.com/resources/articles?topic=software-development
DevOpshttps://github.com/resources/articles?topic=devops
Securityhttps://github.com/resources/articles?topic=security
View all topicshttps://github.com/resources/articles
Customer storieshttps://github.com/customer-stories
Events & webinarshttps://github.com/resources/events
Ebooks & reportshttps://github.com/resources/whitepapers
Business insightshttps://github.com/solutions/executive-insights
GitHub Skillshttps://skills.github.com
Documentationhttps://docs.github.com
Customer supporthttps://support.github.com
Community forumhttps://github.com/orgs/community/discussions
Trust centerhttps://github.com/trust-center
Partnershttps://github.com/partners
GitHub SponsorsFund open source developershttps://github.com/sponsors
Security Labhttps://securitylab.github.com
Maintainer Communityhttps://maintainers.github.com
Acceleratorhttps://github.com/accelerator
Archive Programhttps://archiveprogram.github.com
Topicshttps://github.com/topics
Trendinghttps://github.com/trending
Collectionshttps://github.com/collections
Enterprise platformAI-powered developer platformhttps://github.com/enterprise
GitHub Advanced SecurityEnterprise-grade security featureshttps://github.com/security/advanced-security
Copilot for BusinessEnterprise-grade AI featureshttps://github.com/features/copilot/copilot-business
Premium SupportEnterprise-grade 24/7 supporthttps://github.com/premium-support
Pricinghttps://github.com/pricing
Search syntax tipshttps://docs.github.com/search-github/github-code-search/understanding-github-code-search-syntax
documentationhttps://docs.github.com/search-github/github-code-search/understanding-github-code-search-syntax
Sign in https://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fscijava%2Fnative-lib-loader%2Fissues%2F41
Sign up https://github.com/signup?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F%3Cuser-name%3E%2F%3Crepo-name%3E%2Fvoltron%2Fissues_fragments%2Fissue_layout&source=header-repo&source_repo=scijava%2Fnative-lib-loader
Reloadhttps://github.com/scijava/native-lib-loader/issues/41
Reloadhttps://github.com/scijava/native-lib-loader/issues/41
Reloadhttps://github.com/scijava/native-lib-loader/issues/41
scijava https://github.com/scijava
native-lib-loaderhttps://github.com/scijava/native-lib-loader
Notifications https://github.com/login?return_to=%2Fscijava%2Fnative-lib-loader
Fork 43 https://github.com/login?return_to=%2Fscijava%2Fnative-lib-loader
Star 215 https://github.com/login?return_to=%2Fscijava%2Fnative-lib-loader
Code https://github.com/scijava/native-lib-loader
Issues 8 https://github.com/scijava/native-lib-loader/issues
Pull requests 1 https://github.com/scijava/native-lib-loader/pulls
Actions https://github.com/scijava/native-lib-loader/actions
Projects 0 https://github.com/scijava/native-lib-loader/projects
Wiki https://github.com/scijava/native-lib-loader/wiki
Security Uh oh! There was an error while loading. Please reload this page. https://github.com/scijava/native-lib-loader/security
Please reload this pagehttps://github.com/scijava/native-lib-loader/issues/41
Insights https://github.com/scijava/native-lib-loader/pulse
Code https://github.com/scijava/native-lib-loader
Issues https://github.com/scijava/native-lib-loader/issues
Pull requests https://github.com/scijava/native-lib-loader/pulls
Actions https://github.com/scijava/native-lib-loader/actions
Projects https://github.com/scijava/native-lib-loader/projects
Wiki https://github.com/scijava/native-lib-loader/wiki
Security https://github.com/scijava/native-lib-loader/security
Insights https://github.com/scijava/native-lib-loader/pulse
New issuehttps://github.com/login?return_to=https://github.com/scijava/native-lib-loader/issues/41
New issuehttps://github.com/login?return_to=https://github.com/scijava/native-lib-loader/issues/41
Add ability for static search locationshttps://github.com/scijava/native-lib-loader/issues/41#top
https://github.com/tresf
https://github.com/tresf
tresfhttps://github.com/tresf
on Jul 27, 2021https://github.com/scijava/native-lib-loader/issues/41#issue-954078648
herehttps://github.com/scijava/native-lib-loader/pull/32#issuecomment-887728011
Apple Developer forumshttps://developer.apple.com/forums/thread/22833?answerId=75935022#75935022
Technote 2206 OS X Code Signing In Depthhttps://developer.apple.com/library/mac/technotes/tn2206/_index.html#//apple_ref/doc/uid/DTS40007919-CH1-TNTAG207
System locations will be always be preferredhttps://docs.oracle.com/javase/7/docs/api/java/lang/System.html#loadLibrary(java.lang.String)
native-lib-loader/src/main/java/org/scijava/nativelib/NativeLoader.javahttps://github.com/scijava/native-lib-loader/blob/56cdf6200592e06562cc099e583b1dbbc97db6df/src/main/java/org/scijava/nativelib/NativeLoader.java#L134-L142
56cdf62https://github.com/scijava/native-lib-loader/commit/56cdf6200592e06562cc099e583b1dbbc97db6df
https://github.com
Termshttps://docs.github.com/site-policy/github-terms/github-terms-of-service
Privacyhttps://docs.github.com/site-policy/privacy-policies/github-privacy-statement
Securityhttps://github.com/security
Statushttps://www.githubstatus.com/
Communityhttps://github.community/
Docshttps://docs.github.com/
Contacthttps://support.github.com?tags=dotcom-footer

Viewport: width=device-width


URLs of crawlers that visited me.