Bug 45915 - I18N: ByteEncoding.GetMaxByteCount ignores EncoderFallback.MaxCharCount
Summary: I18N: ByteEncoding.GetMaxByteCount ignores EncoderFallback.MaxCharCount
Alias: None
Product: Class Libraries
Classification: Mono
Component: mscorlib (show other bugs)
Version: master
Hardware: PC All
: --- normal
Target Milestone: Untriaged
Assignee: Bugzilla
Depends on:
Reported: 2016-10-26 12:39 UTC by Oleg
Modified: 2018-03-13 15:09 UTC (History)
4 users (show)

See Also:
Is this bug a regression?: ---
Last known good build:


Description Oleg 2016-10-26 12:39:19 UTC
ByteEncoding.GetMaxByteCount ignores EncoderFallback.MaxCharCount.

Code to reproduce:

    private static void Reproduce()
        var encoding = Encoding.GetEncoding(1251, new MyEncoderFallback(), DecoderFallback.ExceptionFallback);

    private class MyEncoderFallback : EncoderFallback
        public override EncoderFallbackBuffer CreateFallbackBuffer()
            return new MyEncoderFallbackBuffer();

        public override int MaxCharCount => 16;

    private class MyEncoderFallbackBuffer : EncoderFallbackBuffer
        public override int Remaining => 0;

        public override bool Fallback(char charUnknown, int index)
            return true;

        public override bool Fallback(char charUnknownHigh, char charUnknownLow, int index)
            return true;

        public override char GetNextChar()
            return '\0';

        public override bool MovePrevious()
            return false;

It will print 1024 on Mono, 16400 on Windows .NET.

This can cause "Reading would overrun buffer" exception while using StreamWriter with this kind of encodings.

Note You need to log in before you can comment on or make changes to this bug.