Skip to content

Dependency Refactoring: element retriction in api.git - #409

Draft
myungjoo wants to merge 1 commit into
nnstreamer:mainfrom
myungjoo:refactor/elementrestriction
Draft

Dependency Refactoring: element retriction in api.git#409
myungjoo wants to merge 1 commit into
nnstreamer:mainfrom
myungjoo:refactor/elementrestriction

Conversation

@myungjoo

Copy link
Copy Markdown
Member

Element restriction of Inference.Pipeline APIs should be done independently in api.git, not in nnstreamer.git

This addresses nnstreamer/nnstreamer#3553

The next commit should address

  1. unit testing: unittest_capi_inference.cc nnstreamer_capi_util element_available_*

  2. packaging (install the .txt file along with api rpms)

  3. removing restriction mechanisms from nnstreamer.git

Element restriction of Inference.Pipeline APIs should be
done independently in api.git, not in nnstreamer.git

This addresses nnstreamer/nnstreamer#3553

The next commit should address
1. unit testing:
  unittest_capi_inference.cc
    nnstreamer_capi_util
      element_available_*

2. packaging (install the .txt file along with api rpms)

3. removing restriction mechanisms from nnstreamer.git

Signed-off-by: MyungJoo Ham <myungjoo.ham@samsung.com>
@taos-ci

taos-ci commented Oct 17, 2023

Copy link
Copy Markdown
Collaborator

📝 TAOS-CI Version: 1.5.20200925. Thank you for submitting PR #409. Please a submit 1commit/1PR (one commit per one PR) policy to get comments quickly from reviewers. Your PR must pass all verificiation processes of cibot before starting a review process from reviewers. If you are new member to join this project, please read manuals in documentation folder and wiki page. In order to monitor a progress status of your PR in more detail, visit http://ci.nnstreamer.ai/.

@taos-ci

taos-ci commented Oct 17, 2023

Copy link
Copy Markdown
Collaborator

:octocat: cibot: @myungjoo, c/src/ml-api-inference-pipeline.c includes bug(s). Please fix incorrect coding constructs in your commit before entering a review process.

@taos-ci

taos-ci commented Oct 17, 2023

Copy link
Copy Markdown
Collaborator

:octocat: cibot: @myungjoo, A builder checker could not be completed because one of the checkers is not completed. In order to find out a reason, please go to http://ci.nnstreamer.ai/nnstreamer-api/ci/repo-workers/pr-checker/409-202310172342550.85050296783447-058a77f954c47365688e5842573c7278af178493/.

@myungjoo-bot myungjoo-bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Automated review of this draft (transcribed from an AI review agent's report; please verify before acting).

Summary: The commit replaces the nnsconf_get_custom_value_*("element-restriction", ...) lookup in _ml_check_plugin_availability() with a hard-coded allow-list file /etc/ml_inference_pipeline_allowed_elements.txt parsed by new static helpers, so api.git no longer depends on nnstreamer's conf module (nnstreamer/nnstreamer#3553). The direction is still valid and not superseded: main's _ml_check_plugin_availability (c/src/ml-api-inference-pipeline.c:784-833) is identical to the merge-base version, git merge-tree is conflict-free, api.git still has no file-based mechanism, nnstreamer.git still carries the whole mechanism (enable-element-restriction, spec-generated nnstreamer.ini), and issue 3553 is still open. However, this 2023 sketch does not compile, and if it did the allow-check would reject every non-tensor_* element. It needs a rewrite with tests and packaging in the same PR or a stacked series.

All file:line references are PR-side c/src/ml-api-inference-pipeline.c.

  1. [High] Does not compile:844 if (valid_lines_check => valid_lines): => is not a C operator. Fix: >=.
  2. [High] Stray semicolons make the allow-check always fail:878 if (is_element_restriction_valid == FALSE); and :881 if (is_element_restricted == FALSE); are empty statements, so return FALSE; at :879 runs unconditionally. Every element except nnstreamer / tensor_* is reported restricted, ml_pipeline_construct returns ML_ERROR_NOT_SUPPORTED for essentially every test pipeline, and ml_check_element_availability reports everything unavailable. Fix: drop the semicolons; add a test constructing videotestsrc ! tensor_converter ! fakesink with no allow-list present.
  3. [High] printf argument mismatch:822: two %s but only err->message is passed (filepath missing); reads a garbage pointer at runtime. Fix: pass filepath too.
  4. [High] Uninitialized err / contents on the read-failure path:800, :818-825: GError *err; is never NULLed, and if g_file_get_contents fails with err == NULL control falls through to g_strsplit (contents, ...) at :828 with contents uninitialized. Fix: initialize both to NULL and return unconditionally on failure after g_clear_error.
  5. [High] Fail-open default is a Tizen regression given the missing packaging:811-815: file absent => allow everything. No package in api.git installs the .txt (packaging/machine-learning-api.spec has no entry), and nnstreamer's [element-restriction] ini section, still generated on Tizen, is no longer read by anyone after this diff. Net effect on Tizen: restriction silently turns off. Fix: land packaging in the same PR (list generated from the spec %define allowed_element_* macros, root-owned 0644), and on __TIZEN__ treat a missing file as deny (or at least _ml_loge), keeping fail-open only for non-Tizen dev builds.
  6. [Medium] Not thread-safe; reload storm on unreadable file:873-876: allowed_elements and the two flag statics are mutated without a lock; two threads on first use can g_strfreev an array the other is iterating (UAF). When the file exists but is unreadable, is_element_restriction_valid stays FALSE so the file is re-opened for every element of every construct. Fix: load once under g_once_init_enter/leave (or a GMutex), and make the unreadable case terminal (deny all, valid=TRUE).
  7. [Medium] Brittle parsing:828-857: g_strsplit (contents, "\n") leaves \r on CRLF files, trailing whitespace is kept, whitespace-only lines count as elements, # is only honored at column 0, and find_key_strv needs an exact case-folded match so "appsrc\r" never matches. Fix: g_strstrip each line, skip empty / #-prefixed lines after stripping, accumulate into a GPtrArray; this also removes the two-pass count and the "changed at run-time" branch.
  8. [Medium] Existing tests check a different config source than the librarytests/capi/unittest_capi_inference.cc:2382 still gates element_available_01_p on nnsconf_get_custom_value_bool ("element-restriction", ...), which no longer relates to library behavior. Fix: tests that write a temp allow-list via an internal test-only setter (not an env var), and assert allowed/denied, empty file => deny all but tensor_*, comments/CRLF tolerated, file absent => allow all on non-Tizen.
  9. [Low] Identifiers and style__load_allowed_elements / __is_element_allowed (:795, :873): __-prefixed identifiers are reserved in C and the file uses _ml_*; return type on the signature line and gchar *filepath violate gst-indent (what cibot flagged). Typos: "alloed" (:810), "laod" (:845), "retriction" (title).
  10. [Low] No documentation of the file contract — path, one-element-per-line format, # comments, absent => allow all, empty => deny all. Add a short section in Documentation/ and a @remarks on ml_check_element_availability.
  11. [Low] Dependency goal only partially met — the function still relies on find_key_strv from nnstreamer_plugin_api.h, and unittest_capi_inference_single.cc still calls nnsconf_get_custom_value_string in seven places. A local g_strv_contains-style loop would drop find_key_strv too.

No back-door found. The new code consults no environment variable or user-writable path; the only input is a root-owned /etc file. Compared with main it actually removes the NNSTREAMER_CONF env-influenced lookup, which is good; please keep it that way and use an internal test-only setter rather than an env override for tests.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants