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

Off-by-one error in dict_put_impl #939

Open
MPvHarmelen opened this issue Jan 11, 2021 · 1 comment
Open

Off-by-one error in dict_put_impl #939

MPvHarmelen opened this issue Jan 11, 2021 · 1 comment

Comments

@MPvHarmelen
Copy link

There is an off-by-one error in this if-statement:

if ((0 < ht->ht_dict_max_entries) &&
((ht->ht_inserts - ht->ht_deletes) > ht->ht_dict_max_entries) )
goto skip_insertion; /* see below */

Substituting size for inserts - deletions, this statement reads:

if ((0 < ht->ht_dict_max_entries) && (size > ht->ht_dict_max_entries) )
  goto skip_insertion;  /* see below */

which means that the first time an insertion is skipped, size is strictly larger than ht_dict_max_entries, while size should only be allowed to be at most exactly equal to ht_dict_max_entries.

This causes the following query to return 10001 results, even though ResultSetMaxRows is set to 10000 in virtuoso.ini:

CONSTRUCT {
  ?sub ?pred ?obj .
} WHERE {
  ?sub ?pred ?obj .
} LIMIT 10005

The number of results returned by this query is consistently one larger than the value of ResultSetMaxRows.

In turn, this causes the following code to fail to return the X-SPARQL-MaxRows header in the case of construct queries, because length (rset) is actually one larger than maxrows:

if (isvector (rset) and length (rset) = maxrows)
http_header (http_header_get () || sprintf ('X-SPARQL-MaxRows: %d\r\n', maxrows));

MPvHarmelen added a commit to MPvHarmelen/virtuoso-opensource that referenced this issue Jan 11, 2021
MPvHarmelen added a commit to MPvHarmelen/virtuoso-opensource that referenced this issue Jan 12, 2021
MPvHarmelen added a commit to MPvHarmelen/virtuoso-opensource that referenced this issue Jan 12, 2021
MPvHarmelen added a commit to MPvHarmelen/virtuoso-opensource that referenced this issue Jan 13, 2021
@MPvHarmelen
Copy link
Author

Unfortunately it turned out not to be that easy. The off-by-one error is a fact, but wasn't causing the x-sparql-maxrows header not being sent. Instead, the results of a construct query were wrapped inside two one-element lists. See b6a89c7.

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

No branches or pull requests

1 participant