Skip to content

etas: reject extended frames for a filter with "extended": False - #2177

Merged
zariiii9003 merged 1 commit into
hardbyte:mainfrom
bIackr0se:fix/etas-filter-extended-false
Dec 1, 2026
Merged

zariiii9003 merged 1 commit into
hardbyte:mainfrom
bIackr0se:fix/etas-filter-extended-false

Conversation

@bIackr0se

Copy link
Copy Markdown
Contributor

Summary of Changes

This pull request fixes EtasBus._apply_filters in can/interfaces/etas/__init__.py so receive filters with "extended": False reject extended (29-bit) frames.

Previously, an ETAS receive filter such as {"can_id": 0x123, "can_mask": 0x7FF, "extended": False} still let extended frames through when their ID matched can_id and can_mask. For example, an extended frame with ID 0x123 or 0x18FF0123 (0x18FF0123 & 0x7FF == 0x123) passed through. The BusABC.set_filters docstring states that when extended is set, a filter matches only messages where <received_is_extended> == extended. BusABC._matches_filters implements that rule. EtasBus._recv_internal returns (msg, True), meaning the frames are already filtered, so BusABC.recv does not run _matches_filters. The BOA filter installed by _apply_filters is the only filter.

_apply_filters previously checked if filter_.get("extended"): before setting OCI_CAN_MSG_FLAG_EXTENDED in flagsValue and flagsMask. For "extended": False, the extended bit was left out of flagsMask, so the BOA filter ignored the extended flag. With this fix, the extended bit goes into flagsMask whenever "extended" is present in the filter, and it goes into flagsValue only when the value is true. This matches how pack_filters in can/interfaces/socketcan/utils.py handles CAN_EFF_FLAG. Filters without "extended" and filters with "extended": True install the exact same values as before.

-            if filter_.get("extended"):
-                f.flagsValue |= OCI_CAN_MSG_FLAG_EXTENDED
+            if "extended" in filter_:
                 f.flagsMask |= OCI_CAN_MSG_FLAG_EXTENDED
+                if filter_["extended"]:
+                    f.flagsValue |= OCI_CAN_MSG_FLAG_EXTENDED

A new test, test_extended_false_filter_rejects_extended_frames, in test/test_etas.py uses the existing stub BOA library and expects the installed filter (0x123, 0x7FF, 0, OCI_CAN_MSG_FLAG_SELFRECEPTION | OCI_CAN_MSG_FLAG_EXTENDED). On main, it fails with [(291, 2047, 0, 4)] != [(291, 2047, 0, 5)]. With this fix, all four tests in test/test_etas.py pass. They also pass with a gc.collect() forced before the stub reads the filters (the PyPy case from #2171).

A script built an EtasBus through the same stub for five filters: standard 0x123/0x7FF with extended absent, True, or False, and 0x18FF0000/0x1FFF0000 with extended True or False. It applied BOA's value/mask rule to five messages and compared each verdict against BusABC._matches_filters. On main, 3 of 25 verdicts differ, all with extended=False and an extended frame:

filter 0x123/0x7FF extended=False, msg 0x123 extended:      BOA accepts, documented rule rejects
filter 0x123/0x7FF extended=False, msg 0x18FF0123 extended: BOA accepts, documented rule rejects
filter 0x18FF0000/0x1FFF0000 extended=False, msg 0x18FF0123 extended: BOA accepts, documented rule rejects

With this fix, 0 differ.

This pull request adds the news fragment doc/changelog.d/2177.fixed.rst.

Related Issues / Pull Requests

This pull request follows up on #2167 and #2171. The "extended": False case was noted in Additional Notes as a separate issue. There is no open issue for it.

Type of Change

  • Bug fix
  • New feature
  • Documentation update
  • Refactoring
  • Other (please describe):

Checklist

  • I have followed the contribution guide.
  • I have added or updated tests as appropriate.
  • I have added or updated documentation as appropriate.
  • I have added a news fragment for towncrier.
  • All checks and tests pass (tox).

Additional Notes

A filter with "extended": False on ETAS now stops receiving extended frames, which is what the BusABC.set_filters docstring promises.

These checks were not run on ETAS hardware; the BOA libraries are Windows-only. The checks run at the OCI call boundary through the stub.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Dec 1, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-12-01T19:29:50.888130Z 3f8d6ad PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@zariiii9003 zariiii9003 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thank you

@zariiii9003
zariiii9003 merged commit 99f26a9 into hardbyte:main Dec 1, 2026
22 of 26 checks passed
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.

2 participants