Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

services/horizon/internal: Fix index out of range for requests with empty named url params. #1973

Merged
merged 5 commits into from
Nov 25, 2019

Conversation

abuiles
Copy link
Contributor

@abuiles abuiles commented Nov 22, 2019

PR Checklist

PR Structure

  • This PR has reasonably narrow scope (if not, break it down into smaller PRs).
  • This PR avoids mixing refactoring changes with feature changes (split into two PRs
    otherwise).
  • This PR's title starts with name of package that is most changed in the PR, ex.
    services/friendbot, or all or doc if the changes are broad or impact many
    packages.

Thoroughness

  • This PR adds tests for the most critical parts of the new functionality or fixes.
  • I've updated any docs (developer docs, .md
    files, etc... affected by this change). Take a look in the docs folder for a given service,
    like this one.

Release planning

  • I've updated the relevant CHANGELOG (here for Horizon) if
    needed with deprecations, added features, breaking changes, and DB schema changes.
  • I've decided if this PR requires a new major/minor version according to
    semver, or if it's mainly a patch change. The PR is targeted at the next
    release branch if it's not a patch change.

What

Fix index out of range for requests with empty named url params #1965

Why

Making a request without passing the named URL params can cause the following error

runtime.boundsError runtime error: index out of range [0] with length 0

This happens because of the way chi processes named params, if you don't pass the require segment, they match against the right URL, but don't push anything in the URL values. This seems like a bug in chi and someone already reported it go-chi/chi#426

This PR fixes our param reader to return early if the number of Keys doesn't match the number of Values in the URLParams and adds regression tests for it.

While fixing this I also added some extra hardening to the account offers action to have proper validation for account_id and use better error messages.

Known limitations

[TODO or N/A]

@cla-bot cla-bot bot added the cla: yes label Nov 22, 2019
@abuiles abuiles changed the base branch from master to release-horizon-v0.24.0 November 22, 2019 16:50
Copy link
Contributor

@bartekn bartekn left a comment

Choose a reason for hiding this comment

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

LGTM! Super strange that chi doesn't use key -> value map instead of two slices.

@abuiles abuiles merged commit c027eee into release-horizon-v0.24.0 Nov 25, 2019
@abuiles abuiles deleted the fix-index-out-of-range branch November 25, 2019 13:19
@abuiles
Copy link
Contributor Author

abuiles commented Nov 25, 2019

@bartekn agree. I subscribed to the issue on chi, so we'll know when it gets fixed or there is more info about it.

@pkieltyka
Copy link

hey guys, author of chi here. we uses slices instead of map for performance reasons when building the matching pattern, its been highly optimized. I'll look into this bug though, as it theoretically should never happen as even if the parameter key isn't passed, it should result in an empty param value.

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