Commit 7faf1a14 by Zhenyao Mo

Fix a mem corruption in ANGLE translator.

Basically outside TCompile::compile(), the global parse context is invalid, and should never be queried. BUG=angle:568 TEST=webgl conformance tests, no crash Change-Id: I5573ce2bf3bf838ab24f59dda00948f60a0b023d Reviewed-on: https://chromium-review.googlesource.com/197178Reviewed-by: 's avatarJamie Madill <jmadill@chromium.org> Reviewed-by: 's avatarKenneth Russell <kbr@chromium.org> Tested-by: 's avatarZhenyao Mo <zmo@chromium.org>
parent 06bcde59
......@@ -28,12 +28,11 @@ bool IsWebGLBasedSpec(ShShaderSpec spec)
return spec == SH_WEBGL_SPEC || spec == SH_CSS_SHADERS_SPEC;
}
size_t GetGlobalMaxTokenSize()
size_t GetGlobalMaxTokenSize(ShShaderSpec spec)
{
TParseContext *parseContext = GetGlobalParseContext();
// WebGL defines a max token legnth of 256, while ES2 leaves max token
// size undefined. ES3 defines a max size of 1024 characters.
if (IsWebGLBasedSpec(parseContext->shaderSpec))
if (IsWebGLBasedSpec(spec))
{
return 256;
}
......@@ -261,7 +260,7 @@ bool TCompiler::compile(const char* const shaderStrings[],
// Cleanup memory.
intermediate.remove(parseContext.treeRoot);
SetGlobalParseContext(NULL);
return success;
}
......
......@@ -75,10 +75,10 @@ public:
ShHashFunction64 getHashFunction() const { return hashFunction; }
NameMap& getNameMap() { return nameMap; }
TSymbolTable& getSymbolTable() { return symbolTable; }
ShShaderSpec getShaderSpec() const { return shaderSpec; }
protected:
ShShaderType getShaderType() const { return shaderType; }
ShShaderSpec getShaderSpec() const { return shaderSpec; }
// Initialize symbol-table with built-in symbols.
bool InitBuiltInSymbolTable(const ShBuiltInResources& resources);
// Clears the results from the previous compilation.
......
......@@ -187,27 +187,27 @@ void ShGetInfo(const ShHandle handle, ShShaderInfo pname, size_t* params)
*params = compiler->getUniforms().size();
break;
case SH_ACTIVE_UNIFORM_MAX_LENGTH:
*params = 1 + GetGlobalMaxTokenSize();
*params = 1 + GetGlobalMaxTokenSize(compiler->getShaderSpec());
break;
case SH_ACTIVE_ATTRIBUTES:
*params = compiler->getAttribs().size();
break;
case SH_ACTIVE_ATTRIBUTE_MAX_LENGTH:
*params = 1 + GetGlobalMaxTokenSize();
*params = 1 + GetGlobalMaxTokenSize(compiler->getShaderSpec());
break;
case SH_VARYINGS:
*params = compiler->getVaryings().size();
break;
case SH_VARYING_MAX_LENGTH:
*params = 1 + GetGlobalMaxTokenSize();
*params = 1 + GetGlobalMaxTokenSize(compiler->getShaderSpec());
break;
case SH_MAPPED_NAME_MAX_LENGTH:
// Use longer length than MAX_SHORTENED_IDENTIFIER_SIZE to
// handle array and struct dereferences.
*params = 1 + GetGlobalMaxTokenSize();
*params = 1 + GetGlobalMaxTokenSize(compiler->getShaderSpec());
break;
case SH_NAME_MAX_LENGTH:
*params = 1 + GetGlobalMaxTokenSize();
*params = 1 + GetGlobalMaxTokenSize(compiler->getShaderSpec());
break;
case SH_HASHED_NAME_MAX_LENGTH:
if (compiler->getHashFunction() == NULL) {
......@@ -315,14 +315,14 @@ void ShGetVariableInfo(const ShHandle handle,
// This size must match that queried by
// SH_ACTIVE_UNIFORM_MAX_LENGTH, SH_ACTIVE_ATTRIBUTE_MAX_LENGTH, SH_VARYING_MAX_LENGTH
// in ShGetInfo, below.
size_t variableLength = 1 + GetGlobalMaxTokenSize();
size_t variableLength = 1 + GetGlobalMaxTokenSize(compiler->getShaderSpec());
ASSERT(checkVariableMaxLengths(handle, variableLength));
strncpy(name, varInfo.name.c_str(), variableLength);
name[variableLength - 1] = 0;
if (mappedName) {
// This size must match that queried by
// SH_MAPPED_NAME_MAX_LENGTH in ShGetInfo, below.
size_t maxMappedNameLength = 1 + GetGlobalMaxTokenSize();
size_t maxMappedNameLength = 1 + GetGlobalMaxTokenSize(compiler->getShaderSpec());
ASSERT(checkMappedNameMaxLength(handle, maxMappedNameLength));
strncpy(mappedName, varInfo.mappedName.c_str(), maxMappedNameLength);
mappedName[maxMappedNameLength - 1] = 0;
......
......@@ -551,7 +551,7 @@ int glslang_scan(size_t count, const char* const string[], const int length[],
if (context->fragmentPrecisionHigh)
context->preprocessor.predefineMacro("GL_FRAGMENT_PRECISION_HIGH", 1);
context->preprocessor.setMaxTokenSize(GetGlobalMaxTokenSize());
context->preprocessor.setMaxTokenSize(GetGlobalMaxTokenSize(context->shaderSpec));
return 0;
}
......
......@@ -3353,7 +3353,7 @@ int glslang_scan(size_t count, const char* const string[], const int length[],
if (context->fragmentPrecisionHigh)
context->preprocessor.predefineMacro("GL_FRAGMENT_PRECISION_HIGH", 1);
context->preprocessor.setMaxTokenSize(GetGlobalMaxTokenSize());
context->preprocessor.setMaxTokenSize(GetGlobalMaxTokenSize(context->shaderSpec));
return 0;
}
......
......@@ -11,9 +11,11 @@
#if !defined(__LENGTH_LIMITS_H)
#define __LENGTH_LIMITS_H 1
#include "GLSLANG/ShaderLang.h"
// These constants are factored out from the rest of the headers to
// make it easier to reference them from the compiler sources.
size_t GetGlobalMaxTokenSize();
size_t GetGlobalMaxTokenSize(ShShaderSpec spec);
#endif // !(defined(__LENGTH_LIMITS_H)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment