DapperLib / DapperLib/Dapper

DbString Length can silently truncate value

Open
#1,390 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

needs-info
Dominant language
C#
Stars
18.4k
Forks
3.7k
Avg merge
5h 8m
Merged PRs (30d)
1

Description

https://github.com/StackExchange/Dapper/blob/61fa083ca3b711067b6b2a0448b156836d696794/Dapper/DynamicParameters.cs#L276

If the DbString Length is set smaller than the value of the actual string, whether or not the IsAnsi flag is true or false, the value passed into the DbString will be silently truncated in the database call.

We experienced this in one of our apps when the value we passed in was greater than the length value specified in the dapper code and the resulting search came back with different data. Our fix was to build our own nuget package that would set the DbString length to the size of the string value.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in Dapper/DynamicParameters.cs at line 276 and inspect how DbString.Length and IsAnsi are applied when parameter values are longer than the configured length. Reproduce the described database-call behavior with an oversized string, then verify that the chosen handling no longer silently truncates the value.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp, sql
Domain
databases
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.