IndexOutOfRangeException in zlib compression of iTextSharp



我在iTextSharp的zlib实现中发现了一个非常烦人且严重的问题。很难复制,因为它取决于进入PDF的实际数据,但在某些情况下,会发生以下异常:

System.IndexOutOfRangeException: Index was outside the bounds of the array.
at System.util.zlib.Tree.d_code(Int32 dist)
at System.util.zlib.Deflate.compress_block(Int16[] ltree, Int16[] dtree)

System.util.zlib.Tree.cs中,显然没有范围检查,只有假设事情永远不会出错。添加以下(byte)转换似乎是一种解决方案:

internal static int d_code(int dist){
  return ((dist) < 256 ? _dist_code[dist] : _dist_code[256+(byte)((dist)>>7)]);
}

最新更新